No results found for the specified position. 20 C# Intermediate Interview Questions & Answers

MockQuestions

C# Intermediate Mock Interview

To help you prepare for your C# Intermediate interview, here are 20 interview questions and answer examples.

Get More Information About Our C# Intermediate Interview Questions

Question 1 of 20

Demonstrate the ways a parameter can be passed to a method in C#

This question shows the developer's understanding of the way C# methods work.

You can pass a parameter as an output parameter. An example of this is in Try methods. The int reference type takes a string-out parameter and determines whether or not it can convert it to an int. These are fundamental aspects of C# so it is imperative that you are familiar with this.

            Console.WriteLine("Please enter your age");
            bool isValid = int.TryParse(Console.ReadLine(), out int age);
            string message = isValid ? $"You are {age} Years old" : "Please enter valid age";
            Console.WriteLine(message); // if a valid int is entered, the out parameter is properly populated by the user input
            Console.ReadKey();

/*
A method with an out parameter is handy when you also want to return a value as well:
	
*/

 public class Program
    {
        public static void Main(string[] args)
        {

	   // Declaring variable
            // without assigning value
            int G;

            // Pass variable G to the method
            // using out keyword
            Sum(out G);

            // Display the value G
            Console.WriteLine("The sum of" +
                    " the value is: {0}", G);

            // Display the result of the calculation of Sum() as well
            Console.WriteLine("The return value of Sum() is " + Sum(out G));

	/**
	 output:  The sum of the value is: 160
         output:  The return value of Sum() is 161	
	**/	

        }

	// Method in which out parameter is passed
        // and this method returns the value of
        // the passed parameter
        public static int Sum(out int G)
        {
            G = 80;
            G += G;

            return G + 1;

        }

}


/**
  When a parameter is passed by reference, any changes made to that parameter is reflected in the value of that parameter when it is referenced again in the call stack
  Note that str changes after the SetValue() method

**/

 public class Program
    {
        public static void Main(string[] args)
        {

	    // Assign string value
            string str = "The original value of str";

            // Pass as a reference parameter
            SetValue(ref str);

            // Display the given string
            Console.WriteLine(str);

	//output:  The original value of str
        //output:  The new value of str

	}

	static void SetValue(ref string str1)
        {

            // Check parameter value
            if (str1 == "The original value of str")
            {
                Console.WriteLine("The original value of str");
            }

            // Assign the new value
            // of the parameter
            str1 = "The new value of str";
        }

     }

Written by on May 6th, 2021

Next Question

20 C# Intermediate Interview Questions & Answers

Below is a list of our C# Intermediate interview questions. Click on any interview question to view our answer advice and answer examples. You may view 5 answer examples before our paywall loads. Afterwards, you'll be asked to upgrade to view the rest of our answers.

  • 1. Demonstrate the ways a parameter can be passed to a method in C#

  • 2. ASP.net - Differentiate between a session object and a cache object

  • 3. ASP.net - Describe the different page validators

  • 4. ASP.net - Explain the page life cycle events

  • 5. ASP.net - What is another method for persisting the state of a page?

  • 6. ASP.net - What is View State?

  • 7. What is the difference between managed and unmanaged code?

  • 8. What does it mean when a class is sealed?

  • 9. What is the Singleton design pattern and provide an example

  • 10. What is meant by method overriding and provide an example

  • 11. What is an interface and what is an appropriate use case for it?

  • 12. What is overloading and show an example

  • 13. Explain how the term, 'using', is referenced in code and how is it used.

  • 14. Show a way in which you can store values of different datatypes in a single data structure.

  • 15. What is a partial class?

  • 16. What is a Windows service and how would you create one?

  • 17. What is a lambda expression?

  • 18. What is LINQ and how would you use it in an application?

  • 19. In what instance would you use to create a Struct versus a Class?

  • 20. What is an Abstract class and what is an appropriate use case for it?