MockQuestions

C# Advanced Mock Interview

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

Get More Information About Our C# Advanced Interview Questions

Question 1 of 20

What is a Generic class and how is it implemented?

This question shows the developer's ability to work with C# classes.

A generic class is a class in which the internal operations are not specific to a particular data type. This is commonly seen in the collections classes (Lists, HashTables, Stacks, etc) in .NET. A use case for creating your own generic class is where you wish to implement a reusable set of methods that are not type-specific by providing type parameters. The more parameters you provide, the more flexible and re-usable your code becomes. Software shops that provide APIs for clients, strive to implement reusability and flexibility.

// Declare the generic class.
    public class GenericList<T>
    {


	// create a generic list to iterate through the added objects
        System.Collections.Generic.List<T> list = new System.Collections.Generic.List<T>();

        public System.Collections.Generic.List<T> MyList
        {

            get
            {
                return list;
            }

        }

        public void Add(T input) {

           
            list.Add(input);
        
        }
    }

class Program
    {
        public static void Main()
        {
	    // Declare a list of type int.
            GenericList<int> list1 = new GenericList<int>();
            list1.Add(1);
            list1.Add(2);

            // Declare a list of type string.
            GenericList<string> list2 = new GenericList<string>();
            list2.Add("First string");
            list2.Add("Second string");

            //Grab the list from list1 
            System.Collections.Generic.List<int> lst1 = list1.MyList;

            //Grab the list from list2 
            System.Collections.Generic.List<string> lst2 = list2.MyList;

            // iterate through the int members in list1
            foreach (int item in lst1)
            {
                Console.WriteLine(item);

            }
            // interate through the string members in list2
            foreach (string item in lst2)
            {
                Console.WriteLine(item);
            }

	}

   }

Written by on May 17th, 2021

Next Question

20 C# Advanced Interview Questions & Answers

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

  • 1. What is a Generic class and how is it implemented?

  • 2. C# 9.0 - Provide an example of using a 'with' expression

  • 3. C# 9.0 - What is an init-only setter?

  • 4. C# 9.0 - What is a record type?

  • 5. How would you access a file directory and iterate through the contents of a particular directory?

  • 6. Provide code that shows how you would iterate over a result set from a database query.

  • 7. When you connect to a database in your code, what are methods you would use to clean up resources no longer needed.

  • 8. You have an application that requires connectivity to SQL Server. Provide code that shows how to accomplish this.

  • 9. Provide an example of a tuple?

  • 10. What is a Nullable value type?

  • 11. Describe the difference between boxing and unboxing.

  • 12. How are Events implemented in C#?

  • 13. What is the difference between async and sync processes?

  • 14. What are the different Thread states?

  • 15. What is Threading?

  • 16. Once an object is persisted through serialization, show an example of how it can be de-serialized.

  • 17. What is serialization and how is it used?

  • 18. What is a 'race' condition?

  • 19. What is reflection?

  • 20. Explain the role of a delegate and provide an example.