Q:

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

belongs to collection: C#.Net find output programs

0

Find the output of C#.Net programs | Operators | Set 3: Enhance the knowledge of C#.Net Operators 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)
        {
            bool ret = false;
            int a=20;
            double pi = 3.14;

            ret = (a==20)&&(Math.PI==pi);

            Console.WriteLine(ret);
        }
    }
}

Question 2:

using System;

namespace Demo
{
    class Program
    {
        //Entry point of the program
        static void Main(string[] args)
        {
            bool ret = false;
            int a=20;
            int b=0;
            string str="www.includehelp.com";

            ret = (a==20)||((b>=str.Length)?true:false);

            Console.WriteLine(ret);
        }
    }
}

Question 3:

using System;

namespace Demo
{
    class Program
    {
        //Entry point of the program
        static void Main(string[] args)
        {
            bool ret = true;

            Console.WriteLine(ret&=true);
        }
    }
}

Question 4:

using System;

namespace Demo
{
    class Program
    {
        //Entry point of the program
        static void Main(string[] args)
        {
            Console.WriteLine(typeof(bool));
            Console.WriteLine(typeof(short));
        }
    }
}

Question 5:

using System;

namespace Demo
{
    class Program
    {
        //Entry point of the program
        static void Main(string[] args)
        {
            int X = (1,2,3,4,5);

            Console.WriteLine(X);
        }
    }
}

All Answers

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

Answer 1:

Output:

False
Press any key to continue . . .

Explanation:

The above program will print False on the console screen. In the above program, we created three variables ret, a, and pi, that are initialized with "false", "20", and "3.14" respectively.

ret = (a==20)&&(Math.PI==pi);

In the above expression, first condition (a==20) will be true, but the second condition (Math.PI==pi) will False, because Math.PI property will return "3.14159265358979" and the value of variable pi is 3.14 that's why False is assigned to the variable ret.

Then the final value of ret that is False will be printed on the console screen.

Answer2 :

Output:

True
Press any key to continue . . .

Explanation:

The above program will print "True" on the console screen. In the above program, we created four variables ret, a, b, and str that are initialized with false, 20, 0, and "www.includehelp.com" respectively.

Let's evaluate the expression:

ret = (a==20)||((b>=str.Length)?true:false);
ret = True||((b>=str.Length)?true:false);

In case of "||" operator, if first condition is True the second will not check. So finally True is assigned to variable ret and will be printed on the console screen.

Answer 3:

Output:

True
Press any key to continue . . .

Explanation:

The above program will print "True" on the console screen. Here, we created a variable ret which is initialized with true.

Console.WriteLine(ret&=true);

Let's evaluate the expression used in WriteLine() method,

ret &=true;
ret =ret &true;
ret =true &true;
ret = true;

Then finally "True" will be printed on the console screen.

Answer 4:

Output:

System.Boolean
System.Int16
Press any key to continue . . .

Explanation:

In the above program, we used the typeof() operator, which is used to return System data types for the built-in C# data type.

Answer 5:

Output:

main.cs(10,21): error CS8135: Tuple literal `(int, int, int, int, int)' 
cannot be converted to type `int'

Explanation:

The above program will generate errors because we cannot use the comma ',' operator for value assignment like this. We use this kind of assignment in C and C++ languages.

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

total answers (1)

C#.Net find output programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C#.Net find output programs (const Keyword) | set ... >>
<< C#.Net find output programs (Operators) | set 2...