My Report

C# Data Types Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Which is the String method used to compare two strings with each other?

2. Verbatim string literal is better used for?

3. What will be the output of the following C# code?

static void Main(string[] args)
{
    string s1 = "Delhi";
    string s2;
    s2 = s1.Insert (6, "Jaipur");
    Console.WriteLine(s2);
}

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

5. What will be the output of the following C# code?

static void Main(string[] args)
{
    { 
        var dayCode = "MTWFS";
        var daysArray = new List<string>();
        var list = new Dictionary<string, string>
        { {"M", "Monday"}, {"T", "Tuesday"}, {"W", "Wednesday"},
          {"R", "Thursday"}, {"F", "Friday"}, {"S", "Saturday"},
          {"U", "Sunday"}
        };
       for (int i = 0,max = dayCode.Length; i < max; i++)
       {
           var tmp = dayCode[i].ToString();
           if (list.ContainsKey(tmp))
           {
               daysArray.Add(list[tmp]);
            }
       }
       Console.WriteLine(string.Join("\n ", daysArray)); 
 }

6. 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();
 }

7. Which of the following C# code is used for conversion of hex to string form?

static void Main(string[] args)
{
    string testString = "MIKA@?&^";
    string normal = ConvertHexToString (hex,  System.Text.Encoding.Unicode);
    Console.WriteLine(normal);
    Console.ReadLine();
}

8. 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);
 

9. What is the Size of 'Char' datatype?

10. Select the appropriate set of C# code for conversion of string to hexa form.

 static void Main(string[] args)
 {
     string teststring = "MIKA@?&";
     string hex = ConvertstringToHex(teststring, system.Text.Encoding.Unicode);
     Console.WriteLine(hex);
 }

11. What will be the output of the following C# string? (Enter a String : BOMBAY).

static void Main(string[] args)
{
    string Str,  Revstr = " "; 
    int Length;
    Console.Write("Enter A String : ");
    Str = Console.ReadLine();
    Length = Str.Length - 1;
    while (Length >= 0)
    {
        Revstr = Revstr + Str[Length];
        Length --;
    }
    Console.WriteLine("Reverse  String  Is  {0}",  Revstr);
    Console.ReadLine();
}

12. 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

13. Correct statement about strings are?

14. For two strings s1 and s2 to be equal, which is the correct way to find if the contents of two strings are equal?

15. 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));
}

 

Start practicing “1000 MCQs on C#”, and once you are ready, you can take tests on all topics by attempting our “C# Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.