π 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. How do you define a method in C#?
Answer:
Explanation:
A method in C# is defined with a return type, followed by the method name and parameters within parentheses.
2. What is the return type of a method that does not return any value?
Answer:
Explanation:
In C#, the 'void' keyword is used as the return type for methods that do not return a value.
3. How can you call a method in C#?
Answer:
Explanation:
Methods are called by specifying the method name followed by parentheses containing any arguments.
4. What are parameters in a C# method?
Answer:
Explanation:
Parameters are variables that are passed into a method to provide input for its execution.
5. Which keyword is used to indicate that a method parameter is optional in C#?
Answer:
Explanation:
The 'params' keyword in C# is used to specify that a method parameter is optional.
6. What is method overloading in C#?
Answer:
Explanation:
Method overloading in C# refers to creating multiple methods with the same name but different parameters.
7. What is the correct way to declare a method that returns an integer in C#?
Answer:
Explanation:
The return type (int) precedes the method name in C# method declarations.
8. How are arguments passed to a method by default in C#?
Answer:
Explanation:
In C#, arguments are passed to methods by value by default, meaning a copy of the value is passed.
9. What keyword is used to define a method that belongs to a class rather than an instance of a class in C#?
Answer:
Explanation:
The 'static' keyword is used to define a method that belongs to a class itself rather than any instance of the class.
10. How can you return multiple values from a method in C#?
Answer:
Explanation:
Multiple values can be returned from a C# method using a struct/class, an array/list, or out/ref parameters.
11. What does the 'ref' keyword do in a C# method signature?
Answer:
Explanation:
The 'ref' keyword allows a method to modify the value of the argument passed to it.
12. What is recursion in C#?
Answer:
Explanation:
Recursion is a programming technique where a method calls itself.
13. What is a constructor in C#?
Answer:
Explanation:
A constructor is a special method in a class that is called when an instance of the class is created, used to initialize objects.
14. Can a C# method return null?
Answer:
Explanation:
In C#, a method can return null if its return type is either a reference type or a nullable value type.
15. What is the difference between 'ref' and 'out' parameters in C#?
Answer:
Explanation:
'ref' parameters require initialization before being passed to a method, whereas 'out' parameters do not require initialization and are intended to return a value.
Comments
Post a Comment
Leave Comment