Find the output of C#.Net programs | Data Types | Set 2: Enhance the knowledge of C#.Net Data Types 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)
{
ubyte A = 10;
ubyte B = 20;
ubyte C = 0;
C = A++ * ++B + 100;
Console.WriteLine("A: " + A);
Console.WriteLine("B: " + B);
Console.WriteLine("C: " + C);
}
}
}
Question 2:
using System;
namespace Demo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
sbyte A = 10;
byte B = 20;
int C = 30;
Console.WriteLine(A.GetType());
Console.WriteLine(B.GetType());
Console.WriteLine(C.GetType());
}
}
}
Question 3:
using System;
namespace Demo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
sbyte A = 10;
if (A.GetType().ToString() == "System.SByte")
Console.WriteLine("Hello");
else
Console.WriteLine("Hiii");
}
}
}
Question 4:
using System;
namespace Demo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
float A = 10;
if (A.GetType().ToString() == "System.Float")
Console.WriteLine("Hello");
else
Console.WriteLine("Hiii");
}
}
}
Question 5:
using System;
namespace MyRefDemo
{
class Program
{
//Entry point of the program
static void Main(string[] args)
{
byte VAL = 0;
byte A = 13;
byte B = 20;
VAL = (byte)(A * B);
Console.WriteLine(VAL);
}
}
}
Answer 1 :
Output:
Explanation:
The above program will generate a syntax error. because ubyte is not a built-in data type in C#.
Answer 2:
Output:
Explanation:
In the above program, we created the variables A, B, and C initialized with 10, 20, and 30, and then print the System types of the variable using the GetType() method.
Answer 3:
Output:
Explanation:
The above program will print "Hello" on the console screen. Here, we created a variable A of sbyte type and initialized with 10. The GetType() method will return System.SByte, and then we convert it into the string and compared with System.SByte. Then "Hello" will be printed on the console screen.
Answer 4:
Output:
Explanation:
The above program will print "Hiii" on the console screen. Here, we created a variable A of float type and initialized with 10. The GetType() method will return System.Single, and then we convert it into the string and compared with System.Float. Then the if condition will false and "Hiii" will be printed on the console screen.
Answer 5:
Output:
Explanation:
The above program will print "4" on the console screen. In the above program, we created three variables VAL, A, and B initialized with 0, 13, and 20.
Let's evaluate the expression,
VAL = (byte)(A * B); VAL = (byte)(13*20); VAL = (byte)(260); VAL = 4;
As we know that the maximum value of a byte variable is 255, and we are assigning 260, then the value will we move in cyclic order. It means the value will move 5 numbers in cyclic order,
255 ->0 ->1 ->2-> 3->4
need an explanation for this answer? contact us directly to get an explanation for this answer