Vidyalelo
C# Programming · all questions

Basic Syntax and Data Types in C Sharp
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

115

Questions

5/6

Page

Pick an option on a question to see the right answer and solution.

What will be the output of the following C# code?
string s1 = " I AM BEST ";
string s2;
s2 = s1.substring (5, 4);
Console.WriteLine (s2);

Select an option to see the answer and solution.

What is the need for 'Conversion of data type' in C#?

Select an option to see the answer and solution.

Scope of variable is related to definition of variable as:
i. Region of code within which variable value is valid and hence can be accessed.
ii. No, relation with region where variable is declared its value is valid in entire scope.

Select an option to see the answer and solution.

What will be the output of the following C# code?
class Program
{
    static void Main(string[] args)
    {
        int i ;
        for ( i = 0; i < 5; i++)
        {
            int j = 0;
            j += i; 
            Console. WriteLine(j);
        }
        Console. WriteLine(i);
        Console. ReadLine();
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    char c = 'g';
    string s = c.ToString();
    string s1 = "I am a human being" + c;
    Console.WriteLine(s1);
    Console.ReadLine();
}

Select an option to see the answer and solution.

DIFFERENCE BETWEEN KEYWORDS 'VAR' AND 'DYNAMIC'?

Select an option to see the answer and solution.

Which of the conversions are valid for the following C# code?
static void Main(string[] args)
{
    int a = 22;
    long b = 44;
    double c = 1.406;
    b = a;
    c = a;
    a = b;
    b = c;
}

Select an option to see the answer and solution.

Select differences between reference type and value type:
i. Memory allocated to 'Value type' is from heap and reference type is from 'System. ValueType'
ii. Memory allocated to 'Value type' is from 'System. ValueType' and reference type is from 'Heap'
iii. Structures, enumerated types derived from 'System. ValueType' are created on stack, hence known as ValueType and all 'classes' are reference type because values are stored on heap

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    const int a = 5;
    const int b = 6;
    for (int i = 1; i <= 5; i++)
    {
        a = a * i;
        b = b * i;
    }
    Console.WriteLine(a);
    Console.WriteLine(b);
    Console.ReadLine();
}

Select an option to see the answer and solution.

A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D, then when this float is stored in memory in which of the following order do these bytes gets stored?

Select an option to see the answer and solution.

Default Type of number without decimal is?

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    string Name = "He is playing in a ground.";
    char[] characters = Name.ToCharArray();
    StringBuilder sb = new StringBuilder();
    for (int i = Name.Length - 1; i >= 0; --i)
    {
        sb.Append(characters[i]);
    }
    Console.Write(sb.ToString());
    Console.ReadLine(); 
}

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    String name = "Dr.Gupta";
    Console.WriteLine("Good Morning" + name);
}

Select an option to see the answer and solution.

Disadvantages of Explicit Conversion are?

Select an option to see the answer and solution.

What will be the output of the following C# code conversion?
static void Main(string[] args)
{
    char a = 'A';
    string b = "a";
    Console.WriteLine(Convert.ToInt32(a));
    Console.WriteLine(Convert.ToInt32(Convert.ToChar(b)));
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the error in the following C# code?
Static Void Main(String[] args)
{
    const int m = 100;
    int n = 10;
    const int k = n / 5 * 100 * n ;
    Console.WriteLine(m * k);
    Console.ReadLine();
}

Select an option to see the answer and solution.

The subset of 'int' data type is . . . . . . . .

Select an option to see the answer and solution.

Select a convenient declaration and initialization of a floating point number:

Select an option to see the answer and solution.

Why strings are of reference type in C#.NET?

Select an option to see the answer and solution.

What will be the output of the following C# code?
class Program
{
    public static void Main(string[] args)
    {
        int i, j;
        i = (j = 5) + 10;
        Console. WriteLine(i);
        Console. WriteLine(j);
        Console. ReadLine();
    }
}

Select an option to see the answer and solution.