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");
}
}
}
Answer 1:
Output:
Explanation:
The above program will generate syntax error because we cannot use variables with sizeof() operator in C#.
Answer 2:
Output:
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:
Explanation:
The above program will generate syntax error because we cannot use greater than '>' operator with strings.
Answer 4:
Output:
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:
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