Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

## C# MCQ Set 1

1. Which of these classes contains only floating point functions?
a) Math
b) Process
c) System
d) Object

Answer: a [Reason:] Math class contains all the floating point functions that are used for geometry, trigonometry, as well as several general purpose methods. Example : sin(), cos(), exp(), sqrt() etc.

2. What will be the output of the given code snippet?

1. ` class Program`
2. ` {`
3. `     static void Main(string[] args)`
4. `     {`
5. `         double x = 2.0;  `
6. `         double y = 3.0;`
7. `         double z = Math.Pow( x, y );`
8. `         Console.WriteLine(z);`
9. `         Console.ReadLine();`
10. `     }`
11. ` }`

a) 2.0
b) 4.0
c) 8
d) 8.0

Answer: c [Reason:] None. Output :8

3. What will be the output of the given code snippet?

1. ` class Program`
2. ` {`
3. `     static void Main(string[] args)`
4. `     {`
5. `         double x = 4.772;`
6. `         double y = 4.76;`
7. `         double z = Math.Max(x, y);`
8. `         Console.WriteLine(z);`
9. `         Console.ReadLine();`
10. `     }`
11. ` }`

a) true
b) false
c) 4.772
d) 4.76

Answer: c [Reason:] None. Output :4.772

4. What is the value of double constant ‘E’ defined in Math class?
a) approximately 3
b) approximately 3.14
c) approximately 2.72
d) approximately 0

Answer: c [Reason:] None.

5. What will be the output of the given code snippet?

1. ` public class A`
2. ` {`
3. `     public int x;`
4. `     public int y;`
5. `     public void display() `
6. `     {`
7. `         Console.WriteLine(x + " " + y);`
8. `     }`
9. ` }`
10. ` class Program`
11. ` {`
12. `     static void Main(string[] args)`
13. `     {`
14. `         A obj1 = new A();`
15. `         A obj2 = new A();`
16. `         obj1.x = 1;`
17. `         obj1.y = 2;`
18. `         obj2 = obj1;`
19. `         obj1.display();`
20. `         obj2.display();`
21. `     }`
22. ` }`

a) 1 2 0 0
b) 1 2 1 2
c) 0 0 0 0
d) Run time exception

Answer: b [Reason:] None. Output : 1 2 1 2

6. What will be the output of the given code snippet?

1. `class Program`
2. `{`
3. `    static void Main(string[] args)`
4. `    {`
5. `        int[] nums = { 1 };`
6. `        var posNums = from n in nums`
7. `                      select Math.Pow(4 ,3);`
8. `        Console.Write("The values in nums: ");`
9. `        foreach (int i in posNums) `
10. `        Console.Write(i + " ");`
11. `        Console.WriteLine();`
12. `        Console.ReadLine();`
13. `    }`
14. `}`

a) Run time error
b) 64
c) Compile time error
d) 81

Answer: b [Reason:] None. Output :64

7. What will be the output of the given code snippet?

1. `class Program`
2. `{`
3. `    static void Main(string[] args)`
4. `    {`
5. `        float x = 3.14F;`
6. `        int y = (int)Math.Abs(x);`
7. `        Console.WriteLine(y);`
8. `        Console.ReadLine();`
9. `    }`
10. `}`

a) Compile time error
b) 3.14
c) 3
d) 4

Answer: c [Reason:] None. Output :3

8. What will be the output of the given code snippet?

1. `class Program`
2. `{`
3. `    static void Main(string[] args)`
4. `    {`
5. `        int x = 5;`
6. `        int y = (int)Math.Pow(x,2);`
7. `        int z = (int)Math.Pow(y, 2);`
8. `        Console.WriteLine(z);`
9. `        Console.ReadLine();`
10. `    }`
11. `}`

a) 25
b) 625
c) Compile time error
d) Run time error

Answer: b [Reason:] y = 25 , z = 25*25 = 625 Output :625

9. What will be the output of the given code snippet?

1. ` class Program`
2. ` {`
3. `     static void Main(string[] args)`
4. `     {`
5. `         int[] nums = {3 ,1 ,2 ,5 ,4};`
6. `         var ltAvg = from n in nums`
7. `                     let x = nums.Average()`
8. `                     where n < x`
9. `                     select n;`
10. `         Console.WriteLine("The average is " + nums.Average());`
11. `         Console.ReadLine();`
12. `     }`
13. ` }`

a) Run time error
b) 3
c) 5
d) Compile time error

Answer: b [Reason:] Built in method of maths class Avg() id used Output :3

10. What will be the output of the given code snippet?

1. `class Program`
2. `{`
3. `    static void Main(string[] args)`
4. `    {`
5. `        int y = (int)Math.Max(4,2);`
6. `        int z = (int)Math.Pow(y, 2);`
7. `        Console.WriteLine(z);`
8. `        Console.ReadLine();`
9. `    }`
10. `}`

a) 4
b) Compile time error
c) 16
d) 89

Answer: c [Reason:] Built in method of maths class, Max() is used to select maximum value among 4 and 2 and then y is squared using Pow() of math class and the value is stored in z. Output :16

## C# MCQ Set 2

1. Which of these data types can be used for a method having a return statement in it?
a) void
b) int
c) float
d) all of the mentioned

Answer: d [Reason:] None.

2. What is the process of defining more than one method in a class differentiated by parameters known as?
a) Function overriding
c) Function doubling
d) None of the mentioned

Answer: b [Reason:] Function overloading is a process of defining more than one method in a class with same name differentiated by function signature i:e return type or parameters type and number. Example – int volume(int length, int width) & int volume(int length, int width, int height) can be used to calculate volume.

3. Which of these methods is executed first before execution of any other thing that takes place in a program?
a) main method
b) finalize method
c) static method
d) private method

Answer: c [Reason:] If a static method is present in the program then it will be executed first, then main will be executed.

4. Which of these can be used to differentiate two or more methods having same name?
a) Parameters data type
b) Number of parameters
c) Return type of method
d) All of the mentioned

Answer: d [Reason:] None.

5. Which of these data types can be used for a method having a return statement in it?
a) void
b) int
c) float
d) all of the mentioned

Answer: d [Reason:] None.

6. What will be the output of the program?

1. `class box `
2. `{`
3. `    int width;`
4. `    int height;`
5. `    int length;`
6. `    int volume;`
7. `    void volume(int height, int length, int width) `
8. `    {`
9. `        volume = width * height * length;`
10. `    } `
11. `}    `
12. `class Prameterized_method`
13. `{`
14. `    public static void main(String args[]) `
15. `    {`
16. `       box obj = new box();`
17. `       obj.height = 1;`
18. `       obj.length = 5;`
19. `       obj.width = 5;`
20. `       obj.volume(3, 2, 1);`
21. `       Console.WriteLine(obj.volume);  `
22. `       Console.ReadLine();      `
23. `    } `
24. `}`

a) 0
b) 1
c) 6
d) 25

Answer: c [Reason:] None. Output :6

7. What will be the output of the given code snippet?

1. `class equality `
2. `{`
3. `    int x;`
4. `    int y;`
5. `    boolean isequal()`
6. `    {`
7. `        return(x == y);  `
8. `    } `
9. `}    `
10. `class Output `
11. `{`
12. `    public static void main(String args[]) `
13. `    {`
14. `       equality obj = new equality();`
15. `       obj.x = 5;`
16. `       obj.y = 5;`
17. `       Console.WriteLine(obj.isequal());`
18. `    } `
19. `}`

a) false
b) true
c) 0
d) 1

Answer: b [Reason:] None. Output :true

8. What will be the output of the given code snippet?

1. ` class equality`
2. ` {`
3. `     public  int x;`
4. `     public int y;`
5. `     public Boolean isequal()`
6. `     {`
7. `         return (x == y);`
8. `     }`
9. ` }    `
10. ` class Program`
11. ` {`
12. `     static void Main(string[] args)`
13. `     {`
14. `         equality obj = new equality();`
15. `         obj.x = 5;`
16. `         obj.y = 5;`
17. `         Console.WriteLine(obj.isequal());`
18. `         Console.ReadLine();`
19. `     }`
20. ` }`

a) false
b) true
c) 0
d) 1

Answer: b [Reason:] None. Output :true

9. What will be the output of the given code snippet?

1. `class box`
2. `{`
3. `    public  int width;`
4. `    public int height;`
5. `    public int length;`
6. `    public  int volume1;`
7. `    public void volume()`
8. `    {`
9. `        volume1 = width * height * length;`
10. `    }`
11. `    public void volume(int x)`
12. `    {`
13. `        volume1 = x;`
14. `    }`
15. `}    `
16. `class Program`
17. `{`
18. `    static void Main(string[] args)`
19. `    {`
20. `        box obj = new box();`
21. `        obj.height = 1;`
22. `        obj.length = 5;`
23. `        obj.width = 5;`
24. `        obj.volume(5);`
25. `        Console.WriteLine(obj.volume1);        `
26. `        Console.ReadLine();`
27. `    }`
28. `}`

a) 0
b) 5
c) 25
d) 26

Answer: b [Reason:] None. Output : 5

10. What will be the output of the given code snippet?

1. `class Program`
2. `{`
3. `    static void Main(string[] args)`
4. `    {`
5. `        int x, y = 1;`
6. `        x = 10;`
7. `        if(x != 10 && x / Convert.ToInt32(0) == 0)`
8. `        Console.WriteLine(y);`
9. `        else`
10. `        Console.WriteLine(++y);`
11. `        Console.ReadLine();`
12. `    }`
13. `}`

a) 1
b) 2
c) Run time error
d) Compile time error

Answer: b [Reason:] Both conditions for if statements are failed and hence statement after else is executed. Output : 2

## C# MCQ Set 3

1. Select the type of multitasking methods that exist:
a) process based
c) only process
d) both process & thread based

Answer: d [Reason:] There are two distinct types of multitasking: process-based and thread-based.

2. Choose the correct statement about process-based multitasking:
a) A feature that allows our computer to run two or more programs concurrently
b) A program that acts as a small unit of code that can be dispatched by the scheduler
c) Only b
d) Both a & b

Answer: d [Reason:] The process-based multitasking is the feature that allows your computer to run two or more programs concurrently. For example, process-based multitasking allows you to run a word processor at the same time you are using a spreadsheet or browsing the Internet.In process-based multitasking, a program is the smallest unit of code that can be dispatched by the scheduler.

3. Choose the statements which indicate the differences between the thread based multitasking and process based multitasking:
a) Process-based multitasking handles the concurrent execution of programs
b) Process-based multitasking handles the concurrent execution of pieces of the same program
c) Thread-based multitasking handles the concurrent execution of programs
d) Thread-based multitasking deals with the concurrent execution of pieces of the same program

Answer: a [Reason:] The differences between process-based and thread-based multitasking can be summarized like this:Process-based multitasking handles the concurrent execution of programs. Thread-based multitasking deals with the concurrent execution of pieces of the same program.

4. What is the advantage of the multithreading program?
a) Enables to utilize the idle and executing time present in most programs
b) Enables to utilize the idle time present in most programs
c) Both a & b
d) Only b

Answer: d [Reason:] The principal advantage of multithreading is that it enables us to write very efficient programs because it lets us utilize the idle time that is present in most programs.

5. Select the two type of threads mentioned in the concept of multithreading:
a) foreground
b) background
c) only foreground
d) both foreground & background

Answer: d [Reason:] None.

6. Number of threads that exists for each of the processes that occurs in the program:
a) atmost 1
b) atleast 1
c) only 1
d) both a & c

Answer: d [Reason:] All processes have at least one thread for execution, which is usually called the main thread because it is the primary thread that is executed when our program begins.From the main thread, we can create other threads.

7. Choose the namespace which supports multithreading programming:
a) System.net
b) System.Linq
d) All of the mentioned

Answer: c [Reason:] The classes that support multithreaded programming are defined in the System.Threading namespace. Thus, you will usually include this statement at the start of any multithreaded program.

8. What does the given code snippet specify?

1. `public Thread(ThreadStart start)`

a) Defines a thread
b) Declaration of a thread constructor
c) Only a
d) Only a & b

Answer: d [Reason:] To create a thread, instantiate an object of type Thread, which is a class defined in System.Threading. The simplest Thread constructor is shown here: public Thread(ThreadStart start) Here, start specifies the method that will be called to begin execution of the thread.In other words, it specifies the thread’s entry point.

9. Which of these classes is used to make a thread?
a) String
b) System
d) Runnable

Answer: c [Reason:] The multithreading system is built upon the Thread class, which encapsulates a thread of execution. The Thread class is sealed, which means that it cannot be inherited. Thread defines several methods and properties that help manage threads.

10. On call of which type of method the new created thread will not start executing?
a) Begin()
b) Start()
c) New()
d) All of the mentioned

Answer: b [Reason:] Once created, the new thread will not start running until you call its Start() method,which is defined by Thread.

11. Which of these method of Thread class is used to Suspend a thread for a period of time?
a) sleep()
b) terminate()
c) suspend()
d) stop()

Answer: a [Reason:] None.

## C# MCQ Set 4

1. What exception is thrown if the URI format is invalid?
a) URLNotFound
b) URLSourceNotFound
c) MalformedURLException
d) UriFormatException

Answer: d [Reason:] None.

2. What exception is thrown if the protocol supported by URI prefix is invalid?
a) URLNotFound
b) URLSourceNotFound
c) UriFormatException
d) NotSupportedException

Answer :d [Reason:] None.

3. What exception is thrown if the user does not have a proper authorization?
a) URLNotFound
b) URLSourceNotFound
c) System.Security.SecurityException
d) All of the mentioned

Answer: c [Reason:] None.

4. Choose the exceptions generated by the Create() method defined by WebRequest:
a) NotSupportedException
b) UriFormatException
c) System.Security.SecurityException
d) All of the mentioned

Answer: d [Reason:] None.

5. Choose the exceptions generated by the GetReponse() method defined by WebRequest:
a) InvalidOperationException
b) ProtocolViolationException
c) WebException
d) All of the mentioned

Answer: d [Reason:] By definition.

6. Select the properties related to the network errors generated by WebException:
a) response
b) get
c) set
d) none of the mentioned

Answer: a [Reason:] WebException has two properties that relate to network errors: Response and Status. We can obtain a reference to the WebResponse object inside an exception handler through the Response property. For the HTTP protocol, this object describes the error. It is defined like this: public WebResponse Response { get; } When an error occurs, we can use the Status property of WebException to find out what went wrong. It is defined like this: public WebExceptionStatus Status {get; }

7. Which of these classes is used for operating on the request from the client to the server?
a) http
b) httpDecoder
c) httpConnection
d) httpd

Answer: d [Reason:] None.

8. Choose the exceptions generated by the GetResponseStream() method defined by WebRequest:
a) ProtocolViolationException
b) ObjectDisposedException
c) IOException
d) All of the mentioned

Answer: d [Reason:] None.

9. Which of these classes is used to create servers that listen to either local or remote client programs?
a) httpServer
b) ServerSockets
d) HttpResponse

Answer: b [Reason:] None.

10. Which of these methods gives the full URL of an URL object?
a) fullHost()
b) getHost()
c) AbsoluteUri
d) toExternalForm()

Answer: c [Reason:] None.

## C# MCQ Set 5

1. What will be the output of the given code snippet?

1. `class Program`
2. `{`
3. `    static void Main(string[] args)`
4. `    {`
5. `        string[] strs = {"alpha", "beta", "gamma"};`
6. `        var chrs = from str in strs`
7. `                   let chrArray = str.ToCharArray()`
8. `                   from ch in chrArray`
9. `                   orderby ch`
10. `                   select ch;`
11. `        Console.WriteLine("The individual characters in sorted order:");`
12. `        foreach (char c in chrs) `
13. `        Console.Write(c + " ");`
14. `        Console.WriteLine();`
15. `        Console.ReadLine();`
16. `    }`
17. `}`

a) a a l h a b g m m a p e t a
b) a a a a a b e g h l m m p t
c) a g h l m m p t a a a a b e
d) Run time error

Answer: b [Reason:] None. Output: a a a a a b e g h l m m p t

2.What will be the output of the given code snippet?

1. ` class Program`
2. ` {`
3. `     static void Main(string[] args)`
4. `     {`
5. `         int[] nums = { 1, -2, 3, 0, -4, 5 };`
6. `         var posNums = nums.Where(n => n > 0).Select(r => r*2).OrderByDescending(r=>r);`
7. `         Console.Write("The positive values in nums: ");`
8. `         foreach(int i in posNums) `
9. `         Console.Write(i + " ");`
10. `         Console.WriteLine();`
11. `         Console.ReadLine();`
12. `     }`
13. ` }`

a) code run successfully prints nothing
b) run time error
c) code run successfully prints multiple of 2
d) compile time error

Answer: c [Reason:] We had created the queries by using query method such as Where() and Select().This creates a query called posNums that creates a sequence of positive values in nums in descending order using the method OrderByDescending(). Output: 10 6 2

3. What will be the output of the given code snippet?

1. ` class Program`
2. ` {`
3. `     static void Main(string[] args)`
4. `     {`
5. `         int[] nums = {3, 1, 2, 5, 4};`
6. `         var ltAvg = from n in nums`
7. `                     let x = nums.Average()`
8. `                     where n < x`
9. `                     select n;`
10. `         Console.WriteLine("The average is " + nums.Average());`
11. `         Console.ReadLine();`
12. `     }`
13. ` }`

a) Run time error
b) 3
c) 5
d) Compile time error

Answer: b [Reason:] Built in method Avg() is used Output: 3

4. What will be the output of the given code snippet?

1. `class Program`
2. `{`
3. `    static void Main(string[] args)`
4. `    {`
5. `        Expression<Func<int, int, bool>>`
6. `        IsFactorExp = (n, d) => (d != 0) ? (n % d) == 0 : false;`
7. `        Func<int, int, bool> IsFactor = IsFactorExp.Compile();`
8. `        if (IsFactor(10, 5))`
9. `        Console.WriteLine("5 is a factor of 10.");`
10. `        if (!IsFactor(343, 7))`
11. `        Console.WriteLine("7 is not a factor of 10.");`
12. `        Console.ReadLine();`
13. `    }`
14. `}`

a) Compile time error
b) Run time error
c) 5 is a factor of 10
7 is not a factor of 10
d) 5 is a factor of 10

Answer: d [Reason:] The current program has introduced the concept of expression tree.An expression tree is a representation of a lambda expression as data.The program illustrates the two key steps in using an expression tree. First, it creates an expression tree by using this statement: Expression> IsFactorExp = (n, d) => (d != 0) ? (n % d) == 0 : false; Second, this constructs a representation of a lambda expression in memory. Output: 5 is a factor of 10

5. Choose the namespace in which Expression trees are encapsulated:
a) System.Linq
b) System.Linq.Expressions
c) System.Text
d) System.Collections.Generic

Answer: b [Reason:] By definition.

6. For the given set of codes, which query will work according to the set of code?

1. `class Program`
2. `{`
3. `    static void Main(string[] args)`
4. `    {`
5. `        int[] nums = { 1, -2, 3, 0, -4, 5 };`
6. `        int len = /*_________________ */`
7. `        Console.WriteLine("The number of positive values in nums: " + len);`
8. `        Console.ReadLine();`
9. `    }`
10. `}`

a) from n in nums where n > 0
select n
b) from n in nums where n > 0
select n.Count()
c) (from n in nums where n > 0
select n).Count();
d) Both b & c

Answer: c [Reason:] None. Output: int len = (from n in nums where n > 0 select n).Count();

7. For the given set of code, what does the output represent?

1. `class Program`
2. `{`
3. `    static void Main(string[] args)`
4. `    {`
5. `        int[] nums = { 1, -2, 3, 0, -4, 5 };`
6. `        var posNums = from n in nums`
7. `                      where n > 0`
8. `                      select n;`
9. `        int len = posNums.Count();`
10. `        Console.WriteLine(len);`
11. `        Console.ReadLine();`
12. `    }`
13. `}`

a) Execution of code with nothing being printed
b) Execution of code with printing all numbers
c) Execution of code with counting total numbers greater than zero
d) Run time error

Answer: c [Reason:] None. Output: 3

8. For the given set of codes, what is the output?

1. ` class Program`
2. ` {`
3. `     static void Main(string[] args)`
4. `     {`
5. `         int[] nums = { 1, -2, 3, 0, -4, 5 };`
6. `         var posNums = nums.Where(n => n < 10).Select(r => r%3);`
7. `         Console.Write("The values in nums: ");`
8. `         foreach (int i in posNums) Console.Write(i + " ");`
9. `         Console.WriteLine();`
10. `         Console.ReadLine();`
11. `     }`
12. ` }`

a) Compile time error
b) Run time error
c) 1 -2 0 0 -1 2
d) 2 -1 0 0 -2 1