Vidyalelo
C# Programming · all questions

Miscellaneous in C Sharp
practice.

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

170

Questions

7/9

Page

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

Among the given pointers which of the following cannot be incremented?

Select an option to see the answer and solution.

What will be the output of given code snippet?
class Program
{
    static void Main(string[] args)
    {
        char []chars = {'a', 'b', 'c'};
        String s = new String(chars);
        String s1 = "abcd";
        int len1 = s1.Length;
        int len2 = s.Length;
        Console.WriteLine(len1 + " " + len2);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

Which of the following statements are incorrect?

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class UnsafeCode
{
    unsafe static void Main()
    {
        int* ptrs = stackalloc int[3];
        ptrs[0] = 1;
        ptrs[1] = 2;
        ptrs[2] = 3;
        for (int i = 2; i >=0; i--)
        Console.WriteLine(ptrs[i]);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What is meant by preprocessor directive in C#.NET?

Select an option to see the answer and solution.

Pointer variable is used to hold the . . . . . . . . of the variable.

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
static void Main(string[] args)
{
    string s1 = " Ixg";
    string s2 = s1.Insert(3,"i");
    string s3 = s2.Insert(5, "o");
    for (int i = 0; i < s3.Length; i++)
    Console.WriteLine(s3[i]);
    Console.ReadLine();
}

Select an option to see the answer and solution.

Which of these access specifiers must be used for class so that it can be inherited by another subclass?

Select an option to see the answer and solution.

Which of these statements is incorrect?

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class UnsafeCode
{
    unsafe static void Main()
    {
        string str = "this is a test";

            fixed (char* p = str)
           {
               for (int i = str.Length-1 ;p[i] != 0 ;i--)
               Console.Write(p[i]);
           }
       Console.ReadLine();
   }
}

Select an option to see the answer and solution.

Choose the method defined by MemberInfo.

Select an option to see the answer and solution.

Which among the following is the correct statement about the using statement used in C#.NET?

Select an option to see the answer and solution.

Which of these methods of class String is used to extract a substring from a String object?

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class Program
{
    static void Main(string[] args)
    {
        char []chars = {'a', 'b', 'c'};
        String s = new String(chars);
        Console.WriteLine(s);
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

If ListBox is the class of System.Windows.Forms namespace. Then, the correct way to create an object of ListBox class is?

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
unsafe static void Main()
{
    int a = 5;
    int b = 5;
    int c = 5;
    int*[] ptr = new int* [3];
    ptr[0] = &a;
    ptr[1] = &b;
    ptr[2] = &c;
    for (a = 0; a < 3; a++)
    {
        c += *ptr[a];
        Console.WriteLine(c);
    }
    Console.ReadLine();
}

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
static void Main(string[] args)
{
    string s1 = "Hello" + "c" + "Sharp";
    Console.WriteLine(s1);
    Console.ReadLine();
}

Select an option to see the answer and solution.

Which of these methods of class String is used to check whether a given string starts with a particular substring or not?

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class static_out
{
    public static int x;
    public  static int y;
    public int add(int a, int b)
    {
        x = a + b;
        y = x + b;
        return 0;
    }
}    
class Program
{
    static void Main(string[] args)
    {
        static_out obj1 = new static_out();
        static_out obj2 = new static_out();   
        int a = 2;
        obj1.add(a, a + 1);
        obj2.add(5, a);
        Console.WriteLine(static_out.x + " " + static_out.y );     
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.

What will be the output of the following C# code snippet?
class MyClass
{
    char ch = 'A';
    int e = 4;
    int k = 9;
    int z = 6;
    public IEnumerator GetEnumerator()
    {
        for (int i = 0; i < 26; i++)
        {
            if (i == e*k /z) yield break; 
            yield return (int)(ch + i);
        }
    }
}
class Program
{
    static void Main(string[] args)
    {
        MyClass mc = new MyClass();
        foreach(int ch in mc)
        Console.Write(ch + " ");
        Console.WriteLine();
        Console.ReadLine();
    }
}

Select an option to see the answer and solution.