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

6/6

Page

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

Choose effective differences between 'Boxing' and 'Unboxing'.

Select an option to see the answer and solution.

Which data type should be more preferred for storing a simple number like 35 to improve execution speed of a program?

Select an option to see the answer and solution.

What will be the output of the following C# code?
public static void Main(string[] args)
{
    int i = 123;
    object o = i;
    i = 456;
    System. Console. WriteLine("The value-type value = {0}", i);
    System. Console. WriteLine("The object-type value = {0}", o);
    Console. ReadLine();
}

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++)
        {
            Console.WriteLine(i);
        }
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Number of digits upto which precision value of float data type is valid?

Select an option to see the answer and solution.

Minimum and Maximum range of values supported by 'float' data type are?

Select an option to see the answer and solution.

What will be Correct Set of C# Code for given data 'a' and 'b' to print output for 'c' as 74?

Options are not available for this question.

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 = 100;
        for (a = 0; a < 5; a++)
        {
            int i = 200;
            Console. WriteLine(a * i);
        }
        Console. ReadLine();
    }
}

Select an option to see the answer and solution.

Given is the code of days(example:"MTWTFSS") which I need to split and hence create a list of days of week in strings( example:"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"). A set of code is given for this purpose but there is the error occurring in that set of code related to the conversion of char to strings. Hence, Select a C# code to solve the given error.
static void Main(string[] args)
{
    var days = "MTWTFSS";
    var daysArray = days.ToCharArray().Cast<string>().ToArray();
    for (var i = 0; i < daysArray.Length; i++)
    {
        switch (daysArray[i])
        {
        case "M":
            daysArray[i] = "Monday";
            break;
        case "T":
            daysArray[i] = "Tuesday";
            break;
        case "W":
            daysArray[i] = "Wednesday";
            break;
        case "R":
            daysArray[i] = "Thursday";
            break;
        case "F":
            daysArray[i] = "Friday";
            break;
        case "S":
            daysArray[i] = "Saturday";
            break;
        case "U":
            daysArray[i] = "Sunday";
            break;
        }
    }
    daysArray[daysArray.Length - 1] = "and " + daysArray[daysArray.Length - 1];
    Console.WriteLine(string.Join(", ", daysArray));
}

Select an option to see the answer and solution.

Does the output remain same or different for both cases?
i.
char l ='k';
float b = 19.0f;
int c;
c = (l / convert.ToInt32(b));
Console.Writeline(c);

ii.
char l ='k';
float b = 19.0f;
int c;
c = Convert.ToInt32(l / b);
console.writeline(c);

Select an option to see the answer and solution.

What will be the output of the following C# code?
static void Main(string[] args)
{
    int a = 5;
    int b = 10;
    int c;
    Console.WriteLine(c = ++ a + b ++);
    Console.WriteLine(b);
    Console.ReadLine();
}

Select an option to see the answer and solution.

Select the correct differences between char and varchar data types?
i. varchar is non unicode and char is unicode character data type
ii. char is 'n' bytes whereas varchar is actual length in bytes of data entered in terms of storage size
iii. varchar is variable in length and char is the fixed length string
iv. For varchar, if a string is less than the maximum length then it is stored in verbatim without any extra characters while for char if a string is less than the set length it is padded with extra characters to equalize its length to given length

Select an option to see the answer and solution.

Arrange the following data type in order of increasing magnitude sbyte, short, long, int.

Select an option to see the answer and solution.

What will be the output of the following C# code?
public static void Main(string[] args)
{
    double ZERO = 0;
    Console.WriteLine("RESULT OF DIVISION BY ZERO IS :{0}",  (0 / ZERO));
    Console.ReadLine();
}

Select an option to see the answer and solution.

Select appropriate difference between decimal, float and double data type in C#?
i. Float and Double are floating binary point types while decimal is a floating decimal point type.
ii. Precision difference for float is '7' digit for double is '15' to '16' digit and for decimal is '28' to '29' digits.
iii. Some values which cannot be exactly represented hence for those values float and double are more appropriate.

Select an option to see the answer and solution.