12.
What will be the output of the following C# code snippet?
class UnsafeCode
{
    unsafe static void Main()
    {
        int[] nums = new int[10];
        fixed (int* p = &nums[0], p2 = nums)
        {
            if (p == p2)
            Console.WriteLine("p and p2 point to same address.");
            Console.ReadLine();
        }
    }
}

13.
Which among the following is the correct way to access all the elements of the Stack collection created using the C#.NET code snippet given below?
Stack st = new Stack();
st.Push(10);
st.Push(20);
st.Push(-5);
st.Push(30);
st.Push(6);

IEnumerable e;
e = st.GetEnumerator();
while (e.MoveNext())
Console.WriteLine(e.Current);

IEnumerator e;
e = st.GetEnumerator();
while(e.MoveNext())
Console.WriteLine(e.Current);

IEnumerable e;
e = st.GetEnumerable();
while(e.MoveNext())
Console.WriteLine(e.Current);

14.
What will be the output of the following C# code snippet?
class UnsafeCode
{
    static void Main()
    {
        int count = 100;
        int? result = null;
        int incr = 10;
        result = count + incr;
        if (result.HasValue)
            Console.WriteLine("result has this value: " + result.Value);
        else
            Console.WriteLine("result has no value");
        Console.ReadLine();
    }
}

15.
What will be the output of the following C# code snippet?
class Program
{
    static void Main(string[] args)
    {
        int[] nums = { 1 };
        var posNums = from n in nums
                      select Math.Pow(4 ,3);
        Console.Write("The values in nums: ");
        foreach (int i in posNums) 
        Console.Write(i + " ");
        Console.WriteLine();
        Console.ReadLine();
    }
}

16.
What will be the output of the following C# code snippet?
class access
{
    public int x;
    private int y;
    public  void cal(int a, int b)
    {
        x = a + 1;
        y = b;
    }
}    
class Program
{
    static void Main(string[] args)
    {
        access obj = new access();   
        obj.cal(2, 3);
        Console.WriteLine(obj.x + " " + obj.y);     
    }
}

17.
What will be the output of the following C# code snippet?
class UnsafeCode
{
    unsafe static void Main()
    {
        char[] arr = { 'A', 'B', 'C', 'D', 'E' };
        fixed (char* P = arr)
        {
            int i;
            for (i = 0 ;i < 5 ;i++)
            if (*P % 2 == 0)
            ++*P;
            else
            (*P)++;
            Console.WriteLine(arr);
        }
        Console.ReadLine();
    }
}

19.
What will be the output of the following C# code snippet?
class Program
{
    static void Main(string[] args)
    {
        String s1 = "Hello i love Csharp";
        StringBuilder s2 = new  StringBuilder(s1);
        Console.WriteLine(s1.Equals(s2));
        Console.ReadLine();
    }
}

20.
A HashTable t maintains a collection of names of states and capital city of each state. Which among the following finds out whether "New delhi" state is present in the collection or not?

Read More Section(Miscellaneous in C Sharp)

Each Section contains maximum 100 MCQs question on Miscellaneous in C Sharp. To get more questions visit other sections.