π Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.
✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.
π Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.
▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube
1. What is C#?
Answer:
Explanation:
C# is a modern, object-oriented programming language developed by Microsoft, widely used for a variety of software applications.
2. Which of the following is a correct variable declaration in C#?
Answer:
Explanation:
In C#, variables are declared with a type (int, in this case), followed by the variable name and an optional assignment.
3. What is the entry point of a C# console application?
Answer:
Explanation:
The Main() method is the entry point of a C# console application, where the program execution begins.
4. How do you create a single-line comment in C#?
Answer:
Explanation:
In C#, single-line comments are created using two forward slashes (//).
5. What is the correct way to declare a constant in C#?
Answer:
Explanation:
Constants in C# are declared using the 'const' keyword followed by the data type and the constant name.
6. Which keyword is used to define a class in C#?
Answer:
Explanation:
The 'class' keyword is used to define a class in C#.
7. How do you handle exceptions in C#?
Answer:
Explanation:
Exceptions in C# are handled using a try-catch block, where 'try' contains the code that might throw an exception, and 'catch' is used to handle the exception.
8. Which collection type automatically resizes in C#?
Answer:
Explanation:
The List<> collection in C# automatically resizes as elements are added or removed.
9. How do you concatenate strings in C#?
Answer:
Explanation:
Strings can be concatenated using the '+' operator in C#.
10. What is LINQ in C#?
Answer:
Explanation:
LINQ (Language Integrated Query) is a feature in C# that provides a query syntax for querying data sources like arrays, collections, databases, etc.
11. What is the output of the following code?
int x = 5;
int y = x++;
Answer:
Explanation:
The post-increment operator (x++) increases x after its current value has been assigned to y. So, y gets 5, and then x becomes 6.
12. What is an interface in C#?
Answer:
Explanation:
An interface in C# defines a contract (a set of method and property definitions) that implementing classes must adhere to.
13. What does the 'static' keyword denote in C#?
Answer:
Explanation:
The 'static' keyword in C# denotes that a member (method or variable) belongs to the class itself, rather than to any specific instance of the class.
14. Which of the following data types is a reference type in C#?
Answer:
Explanation:
In C#, strings are reference types, whereas int, double, and bool are value types.
15. How do you declare an array in C#?
Answer:
Explanation:
In C#, arrays are declared with the type followed by square brackets, then the variable name, and finally the 'new' keyword with the array size.
16. What is the purpose of the 'using' directive in C#?
Answer:
Explanation:
The 'using' directive in C# is used to include a namespace in a file, allowing the use of types defined in that namespace.
17. What does the 'void' keyword signify in a method declaration?
Answer:
Explanation:
In C#, the 'void' keyword in a method declaration indicates that the method does not return any value.
18. What are generics in C#?
Answer:
Explanation:
Generics in C# allow the creation of methods and classes with the flexibility to work with any data type (specified as a generic parameter).
19. How do you implement inheritance in C#?
Answer:
Explanation:
Inheritance in C# is implemented by using the ':' operator followed by the base class name.
20. What is a delegate in C#?
Answer:
Explanation:
A delegate in C# is a type that represents references to methods with a particular parameter list and return type.
21. What is the scope of a variable declared inside a method in C#?
Answer:
Explanation:
Variables declared inside a method in C# have a scope that is local to the method.
22. What is a constructor in C#?
Answer:
Explanation:
A constructor is a special method in C# that is called automatically when an instance of a class is created. It is used to initialize the object.
23. What are properties in C#?
Answer:
Explanation:
Properties in C# are special methods that provide a way to read, write, or compute values of private fields.
24. How can you make a class abstract in C#?
Answer:
Explanation:
In C#, a class is made abstract by using the 'abstract' keyword, which means it cannot be instantiated directly and must be inherited.
25. What does 'namespace' represent in C#?
Answer:
Explanation:
A namespace in C# provides a way to logically organize your code. It is a container for classes, interfaces, structs, and other namespaces.
26. How do you handle a null reference exception in C#?
Answer:
Explanation:
Handling null reference exceptions can be done using try-catch blocks for exception handling, using if-else statements to check for null before accessing members, or a combination of both.
27. What is the purpose of the 'ToString' method in C#?
Answer:
Explanation:
The 'ToString' method is used to convert an object to its string representation, and it can be overridden to provide meaningful string output for a class.
28. How are method parameters passed in C# by default?
Answer:
Explanation:
In C#, method parameters are passed by value by default. This means a copy of the value is passed to the method.
29. What is the purpose of the 'ref' keyword in method parameters?
Answer:
Explanation:
The 'ref' keyword is used in C# to pass a parameter by reference, allowing the method to modify the original variable.
30. What is an indexer in C#?
Answer:
Explanation:
Indexers in C# provide a way to access elements in an object that represents a collection using array-like syntax.
31. What are events in C#?
Answer:
Explanation:
Events in C# are a way for an object to notify other objects when something of interest occurs, such as user interactions.
32. What is the purpose of the 'out' keyword in method parameters?
Answer:
Explanation:
The 'out' keyword is used for parameters that the method will use to return data back to the caller.
33. What is a namespace alias in C#?
Answer:
Explanation:
A namespace alias in C# allows you to provide an alternative name for a namespace, simplifying code when dealing with namespaces having long names.
34. What is the use of the 'partial' keyword in C#?
Answer:
Explanation:
The 'partial' keyword allows the definition of a class, struct, or method to be divided across multiple files, facilitating better organization and maintainability.
35. What is boxing in C#?
Answer:
Explanation:
Boxing in C# is the process of converting a value type (like int or double) to a reference type, typically to an Object or to an interface type.
Comments
Post a Comment
Leave Comment