Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

1. Which of the following is the correct syntax to declare a variable in C#?

- A) int x;
- B) int x = 10;
- C) var x = 10;
- D) All of the above
- Answer: D) All of the above

2. Which keyword is used to handle exceptions in C#?


- A) catch
- B) try
- C) throw
- D) handle
- Answer: B) try

3. Which of the following is the correct way to create an object of the `Person` class in C#?
- A) Person p = new Person();
- B) Person p;
- C) p = Person();
- D) new Person p;
- Answer: A) Person p = new Person();

4. Which of the following access modi ers makes a member accessible only within its own class?
- A) public
- B) private
- C) protected
- D) internal
- Answer: B) private

5. Which of the following methods is used to start a thread in C#?


- A) Start()
- B) Run()
- C) Begin()
- D) Execute()
- Answer: A) Start()

6. Which of the following is a value type in C#?


- A) int
- B) string
- C) object
- D) dynamic
- Answer: A) int

7. What is the output of the following C# code?

```csharp
int a = 5;
int b = 10;
Console.WriteLine(a + b);
```
- A) 510
- B) 15
- C) 5 + 10
- D) Error
- Answer: B) 15

8. Which of the following statements is correct about constructors in C#?


- A) Constructors do not have a return type.
- B) Constructors can be overloaded.
- C) Constructors are called automatically when an object is created.
fi
- D) All of the above
- Answer: D) All of the above

9. Which of the following is the correct way to create a method in C#?


- A) void MyMethod() { }
- B) void MyMethod { }
- C) MyMethod() { }
- D) void MyMethod(void) { }
- Answer: A) void MyMethod() { }

10. Which of the following LINQ methods is used to lter elements in a collection?
- A) Select
- B) Where
- C) OrderBy
- D) GroupBy
- Answer: B) Where
fi

You might also like