locked
C# simple Question RRS feed

  • Question

  • I need to write a simple C# code to implement the following. Can you help?

    if any of codes A or B is applied on a document and none of X or Y or T or H or P is applied then, return false

    and the other rule is the opposite,

    i.e

    if any of codes X or Y or T or H or P is applied on a document and none of A or B, then return false

    help help help help please

    Regards,


    ebro

    Tuesday, August 13, 2013 5:06 PM

Answers

  • Try this

       class Program
        {
            static string document = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            static string codeA = "A";
            static string codeB = "B";
            static string codeH = "H";
            static string codeP = "P";
            static string codeT = "T";
            static string codeX = "X";
            static string codeY = "Y";
            static void Main(string[] args)
            {
            }
            static bool function1()
            {
                //if any of codes A or B is applied on a document and none of X or Y or T or H or P is applied then, return false
                if ((document.Contains(codeA) || document.Contains(codeB)) &&
                    !(document.Contains(codeX) || document.Contains(codeY) || document.Contains(codeT) || 
                      document.Contains(codeH) || document.Contains(codeP)))
                    return false;
                else
                    return true;
            }
            static bool function2()
            {
                //if any of codes X or Y or T or H or P is applied on a document and none of A or B, then return false 
                if ((document.Contains(codeX) || document.Contains(codeY) ||
                     document.Contains(codeT) || document.Contains(codeH) || document.Contains(codeP)) &&
                      !(document.Contains(codeH) || document.Contains(codeA)))
                    return false;
                else
                    return true;
            }
        }


    jdweng

    • Proposed as answer by Elmar Boye Tuesday, August 13, 2013 7:41 PM
    • Marked as answer by ebrolove Tuesday, August 13, 2013 8:10 PM
    Tuesday, August 13, 2013 5:43 PM

All replies

  • Try this

       class Program
        {
            static string document = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            static string codeA = "A";
            static string codeB = "B";
            static string codeH = "H";
            static string codeP = "P";
            static string codeT = "T";
            static string codeX = "X";
            static string codeY = "Y";
            static void Main(string[] args)
            {
            }
            static bool function1()
            {
                //if any of codes A or B is applied on a document and none of X or Y or T or H or P is applied then, return false
                if ((document.Contains(codeA) || document.Contains(codeB)) &&
                    !(document.Contains(codeX) || document.Contains(codeY) || document.Contains(codeT) || 
                      document.Contains(codeH) || document.Contains(codeP)))
                    return false;
                else
                    return true;
            }
            static bool function2()
            {
                //if any of codes X or Y or T or H or P is applied on a document and none of A or B, then return false 
                if ((document.Contains(codeX) || document.Contains(codeY) ||
                     document.Contains(codeT) || document.Contains(codeH) || document.Contains(codeP)) &&
                      !(document.Contains(codeH) || document.Contains(codeA)))
                    return false;
                else
                    return true;
            }
        }


    jdweng

    • Proposed as answer by Elmar Boye Tuesday, August 13, 2013 7:41 PM
    • Marked as answer by ebrolove Tuesday, August 13, 2013 8:10 PM
    Tuesday, August 13, 2013 5:43 PM
  • You just saved my job man!

    Thank you so much,


    ebro

    Tuesday, August 13, 2013 6:10 PM