C# Set 6 (30 mcqs)

1. Select the namespace on which the stream classes are defined?
a) System.IO
b) System.Input
c) System.Output
d) All of the mentioned

2. Choose the class on which all stream classes are defined?
a) System.IO.stream
b) Sytem.Input.stream
c) System.Output.stream
d) All of the mentioned

3. Choose the stream class method which is used to close the connection:
a) close()
b) static close()
c) void close()
d) none of the mentioned

4. A method used to write a single byte to an output stream?
a) void WriteByte(byte value)
b) int Write(byte[] buffer ,int offset ,int count)
c) write()
d) None of the mentioned

5. Select the method which writes the contents of the stream to the physical device.
a) fflush()
b) void fflush()
c) void Flush()
d) flush()

6. Select the method which returns the number of bytes from the array buffer:
a) void WriteByte(byte value)
b) int Write(byte[] buffer ,int offset ,int count)
c) write()
d) None of the mentioned

7. Name the method which returns integer as -1 when the end of file is encountered.
a) int read()
b) int ReadByte()
c) void readbyte()
d) None of the mentioned

8. Select the statements which defines the stream.
a) A stream is an abstraction that produces or consumes information
b) A stream is linked to a physical device by the I/0 system
c) C# programs perform I/O through streams
d) All of the mentioned

9. Select the action of the method long seek()?
a) Attempts to readup to count bytes into buffer starting at buffer[offset]
b) Writes a single byte to an output stream
c) Sets the current position in the stream to the specified offset from specified origin and hence returns the new position
d) None of the mentioned

10. Attempts to read up to count bytes into buffer starting at buffer[offset], returning the number of bytes successfully read?
a) int ReadByte()
b) int Read(byte[] buffer ,int offset ,int count)
c) Void WriteByte(byte value)
d) None of the mentioned

11. Choose the correct way to call subroutine fun() of the sample class?
1.class a
2.{
3.    public void x(int p, double k)
4.    {
5.        Console.WriteLine(“k : csharp!”);
6.    }
7.}
a) delegate void del(int i);
x s = new x();
del d = new del(ref s.x);
d(8, 2.2f);
b) delegate void del(int p, double k);
del d;
x s = new x();
d = new del(ref s.x);
d(8, 2.2f);
c) x s = new x();
delegate void d = new del(ref x);
d(8, 2.2f);
d) all of the mentioned

12. Which is the correct way to call the function abc() of the given class csharp given below?
1.class csharp
2.{
3.    public int abc(int a)
4.    {
5.        Console.WriteLine(“A:Just do it!”);
6.        return 0;
7.    }
8.}
a) delegate void del(int a);
csharp s = new csharp();
del d = new del(ref s.abc);
d(10);
b) csharp s = new csharp();
delegate void d = new del(ref abc);
d(10);
c) delegate int del(int a);
del d;
csharp s = new csharp();
d = new del(ref s.fun);
d(10);
d) none of the mentioned

13. Which is the correct way to call the subroutine function abc() of the given class csharp given below?
1.class csharp
2.{
3.    void abc()
4.    {
5.        console.writeline(“A:Just do it!”);
6.    }
7.}
a) csharp c = new csharp();
delegate void d = new del(ref abc);
d();
b) delegate void del();
del d;
csharp s = new csharp();
d = new del(ref s.abc);
d();
c) delegate void del();
abc s = new abc();
del d = new del(ref s.abc);
d();
d) csharp s = new csharp();
delegate void del = new delegate(ref abc);
del();

14. What will be the output of the given code snippet below?
1.{
2.    delegate void A(ref string str);
3.    class sample
4.    {
5.        public static void fun( ref string a)
6.        {
7.            a = a.Substring( 7, a.Length – 7);
8.        }
9.    }
10.    class Program
11.    {
12.        static void Main(string[] args)
13.        {
14.            A str1;
15.            string str = “Test Your C#.net skills”;
16.            str1 = sample.fun;
17.            str1(ref str);
18.            Console.WriteLine(str);
19.        }
20.    }
21.}
a) Test Your
b) ur C#.NET
c) ur C#.NET Skills
d) None of the mentioned

15. What will be the output of the given code snippet below?
1.{
2.    delegate string F(string str);
3.    class sample
4.    {
5.        public static string fun(string a)
6.        {
7.            return a.Replace(‘,”-‘);
8.        }
9.    }
10.    class Program
11.    {
12.        static void Main(string[] args)
13.        {
14.            F str1 = new F(sample.fun);
15.            string str = str1(“Test Your c#.NET skills”);
16.            Console.WriteLine(str);
17.        }
18.    }
19.}
a) Test Your
b) Test-Your-C#.NET-Skills
c) ur C#.NET Skills
d) None of the mentioned

16. Choose the statements which makes delegate in C#.NET different than a normal class?
a) Delegates in C#.NET is a base class for all delegates type
b) From Delegates created in C#.NET further not allowed to derive from the delegate types that are created
c) Only system and compilers can derive explicitly from the Delegate or MulticasteDelegate class
d) All of the mentioned

17. Which are the correct statement about delegates?
a) Delegates can be used to implement callback notification
b) Delegates permit execution of a method on a secondary thread in an asynchronous manner
d) Delegate is a user defined type
e) None of the mentioned

18. What will be the output of given set of code?
1.{
2. delegate string f(string str);
3. class sample
4. {
5.     public static string fun(string a)
6.     {
7.         return a.Replace(‘k’, ‘o’);
8.     }
9. }
10. class Program
11. {
12.     static void Main(string[] args)
13.     {
14.         f str1 = new f(sample.fun);
15.         string str = str1(“Test Ykur C#.NET Skills”);
16.         Console.WriteLine(str);
17.         Console.ReadLine();
18.     }
19. }
20.}
a) Test Ykur C#.NET Skills
b) Test Ykour C#.NET Skills
c) Test Your C#.NET Skills
d) Test ur C#.NET Skills

19. Incorrect statement about delegates are?
a) Delegates are reference types
b) Delegates are object oriented
c) Delegates are type safe
d) Only one method can be called using a delegate

20. Select the modifiers which controls the accessibility of the delegate:
a) new
b) protected
c) public
d) internal

21. What will be the output of given code snippet?
1.class UnsafeCode
2.{
3.    struct MyStruct
4.    {
5.        public int a;
6.        public int b;
7.        public int Sum()
8.       {
9.           return a * b;
10.       }
11.   }
12.   unsafe static void Main()
13.   {
14.       MyStruct o = new MyStruct();
15.       MyStruct* p;
16.       p = &o;
17.       p->a = 10;
18.       p->b = 20;
19.       Console.WriteLine(“Value is ” + p->Sum());
20.       Console.ReadLine();
21.   }
22.}
a) Compile time error
b) Run time error
c) 200
d) 30

22. What will be the output of given code snippet?
1.class UnsafeCode
2.{
3.    struct MyStruct
4.    {
5.        public int a;
6.        public int b;
7.        public int Sum()
8.       {
9.           return a / b;
10.       }
11.   }
12.   unsafe static void Main()
13.   {
14.       MyStruct o = new MyStruct();
15.       MyStruct* p;
16.       p = &o;
17.       p->a = 60;
18.       p->b = 15;
19.       int c = 30;
20.       Console.WriteLine(“Value is : ” + p->Sum()*c);
21.       Console.ReadLine();
22.   }
23.}
a) Compile time error
b) 120
c) Run time error
d) 4

23. What will be the output of given code snippet?
1.class UnsafeCode
2.{
3.    unsafe static void Main()
4.    {
5.        int[] nums = new int[10];
6.        fixed (int* p = &nums[0], p2 = nums)
7.        {
8.            if (p == p2)
9.            Console.WriteLine(“p and p2 point to same address.”);
10.            Console.ReadLine();
11.        }
12.    }
13.}
a) Run time error
b) Compile time error
c) p and p2 point to same address
d) Only b

24. What will be the output of given code snippet?
1.class UnsafeCode
2.{
3.    static void Main()
4.    {
5.        int? count = null;
6.        int? result = null;
7.        int incr = 10;
8.        result = count + incr;
9.        if (result.HasValue)
10.            Console.WriteLine(“result has this value: ” + result.Value);
11.        else
12.            Console.WriteLine(“result has no value”);
13.        Console.ReadLine();
14.    }
15.}
a) Run time error
b) 0
c) result has no value
d) Compile time error

25. What will be the output of given code snippet?
1.class UnsafeCode
2.{
3.    static void Main()
4.    {
5.        int count = 100;
6.        int? result = null;
7.        int incr = 10;
8.        result = count + incr;
9.        if (result.HasValue)
10.            Console.WriteLine(“result has this value: ” + result.Value);
11.        else
12.            Console.WriteLine(“result has no value”);
13.        Console.ReadLine();
14.    }
15.}
a) Run time error
b) 110
c) result has no value
d) Compile time error

26. Choose the statement which defines the Nullable type Correctly:
a) a special version of a value type that is represented by a structure
b) a nullable type can also store the value null
c) Nullable types are objects of System.Nullable, where T must be a non nullable value type
d) None of the mentioned

27. What does the following code depicts?
1. System.Nullable count;
2. bool? done;
a) code 1 declares the objects of nullable of type Nullable defined in the System namespace
b) code 2 declares a nullable type in much shorter and in more commonly used way using ‘?’
c) Both a & b
d) None of the mentioned

28. Which operator is commanly used to find the size of the type of C#?
a) size()
b) sizeof(type)
c) Both a & b
d) None of the mentioned

29. What will be the output of given code snippet?
1. unsafe struct FixedBankRecord
2. {
3.     public fixed byte Name[80];
4.     public double Balance;
5.     public long ID;
6. }
7. class UnsafeCode
8. {
9.     unsafe static void Main()
10.     {
11.         Console.WriteLine(“Size of FixedBankRecord is ” + sizeof(FixedBankRecord));
12.         Console.ReadLine();
13.     }
14. }
a) Run time error
b) 80
c) 96
d) Compile time error

30. What will be the output of given code snippet?
1.class UnsafeCode
2.{
3.    unsafe static void Main()
4.    {
5.        int* ptrs = stackalloc int[3];
6.        ptrs[0] = 1;
7.        ptrs[1] = 2;
8.        ptrs[2] = 3;
9.        for (int i = 2; i >=0; i–)
10.        Console.WriteLine(ptrs[i]);
11.        Console.ReadLine();
12.    }
13.}
a) 3 2 1
b) 1 2 3
c) None of the mentioned
d) run time error

Answers

1-a 2-a 3-c 4-a 5-c
6-b 7-b 8-d 9-c 10-b
11-b 12-c 13-b,c 14-c 15-b
16-d 17-a,b,c 18-c 19-d 20-a,b,c,d
21-c 22-b 23-c 24-c 25-a
26-a,b,c 27-c 28-b 29-c 30-a

Sharing is caring!

Leave a Comment

Your email address will not be published. Required fields are marked *

shares