Q:

C#.Net find output programs (if else) | set 3

0

Find the output of C#.Net programs | if else | Set 3: Enhance the knowledge of C#.Net if else concepts by solving and finding the output of some C#.Net programs.

Question 1:

using System;

namespace Demo
{
    class Program
    {
        //Entry point of the program
        static void Main(string[] args)
        {
            int   A = 20;
            float B = 20.0F;

            if (sizeof(A) == sizeof(B))
                Console.WriteLine("Hello");
            else
                Console.WriteLine("Hiii");
        }
    }
}

Question 2:

using System;

namespace Demo
{
    class Program
    {
        //Entry point of the program
        static void Main(string[] args)
        {
            double   A = 20.23;
            float    B = 20.23F;

            if (A>B)
                Console.WriteLine("Hello");
            else
                Console.WriteLine("Hiii");
        }
    }
}

Question 3:

using System;

namespace Demo
{
    class Program
    {
        //Entry point of the program
        static void Main(string[] args)
        {
            string STR1 = "HELLO";
            string STR2 = "hello";

            if (STR1>STR2)
                Console.WriteLine("WWW.INCLUDEHELP.COM");
            else
                Console.WriteLine("WWW.GOOGLE.COM");
        }
    }
}

Question 4:

using System;

namespace Demo
{
    class Program
    {
        //Entry point of the program
        static void Main(string[] args)
        {
            string STR1 = "HELLO";
            string STR2 = "hello";

            if (STR1==STR2)
                Console.WriteLine("WWW.INCLUDEHELP.COM");
            else
                Console.WriteLine("WWW.GOOGLE.COM");
        }
    }
}

Question 5:

using System;

namespace Demo
{
    class Program
    {
        //Entry point of the program
        static void Main(string[] args)
        {
            string STR1 = "HELLO";
            string STR2 = "hello";

            if (STR1 == STR2.ToUpper())
                Console.WriteLine("WWW.INCLUDEHELP.COM");
            else
                Console.WriteLine("WWW.GOOGLE.COM");
        }
    }
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer 1:

Output:

main.cs(13,24): error CS0246: The type or namespace name `A' could not be found.
Are you missing an assembly reference?

Explanation:

The above program will generate syntax error because we cannot use variables with sizeof() operator in C#.

Answer 2:

Output:

Hello
Press any key to continue . . .

Explanation:

The above program will print "Hello" on the console screen. Because A is the double type and B is float type. In C#, a double number is always treated bigger in case of equality. That's why the If condition will true and print "Hello" on the console screen.

Answer 3:

Output:

main.cs(13,17): error CS0019: Operator `>' cannot be applied to 
operands of type `string' and `string'

Explanation:

The above program will generate syntax error because we cannot use greater than '>' operator with strings.

Answer 4:

Output:

WWW.GOOGLE.COM
Press any key to continue . . .

Explanation:

The above program will print "WWW.GOOGLE.COM" on the console screen. Because STR1 and STR2 do not contain the same values. That's why condition will false and else part will execute.

Answer5:

Output:

WWW.INCLUDEHELP.COM
Press any key to continue . . .

Explanation:

The above program will print "WWW.INCLUDEHELP.COM" on the console screen. Here, we declared two string variables STR1 and STR2 initialized with "HELLO" and "hello" respectively.

Here, we used the ToUpper() method that will return "HELLO" then the condition will be true and print "WWW.INCLUDEHELP.COM" on the console screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now