Denis Panjuta

The technical job market is competitive and software developers of all experience levels should take the time before an interview to refresh themselves on key skills and common interview questions. In this article, I’ll help you prepare to ace your next interview with these questions related to the C# programming language

These 50 essential C# questions and answers will help you understand the technical concepts of the language so that you walk into a meeting with the hiring manager with confidence. As a developer myself, I use these concepts daily. 

Complete C# Masterclass

Last Updated January 2021

  • 260 lectures
  • All Levels
4.5 (11,836)

Learn C# Programming – WPF, Databases, Linq, Collections, Game Development with Unity. More than just the C# basics! | By Denis Panjuta, Tutorials.eu by Denis Panjuta

Explore Course
  1. What is a class?

A class is a template to create an object. It contains properties as well as methods. We can create many instances of objects from a single class.

Below is an example of a class:

public class Student
    	{
        //data members
        public int rollNumber { get; set; }
        public string fullName { get; set; }

        //function
        public void PrintDetails()
        {
            //login of function
        }
 }
  1. What are the main concepts of object-oriented programming?

Encapsulation, abstraction, polymorphism, and inheritance are the main concepts of object-oriented programming.

  1. What is an object?

An object is an instance of a class through which we access the functions of that class. We can use the “new” keyword to create an object. A class that creates an object in memory holds information about the functions, data members, and behavior of that class.

See the syntax of an object below.

//Class
    	public class Employee
    	{
        //private members
        private string fName { get; set; }
        private string lName { get; set; }

        //function
        public void Display()
        {
            Console.WriteLine("Full name is {0} {1}", fName, lName);
        }

        public void SetName(string firstName, string lastName)
        {
            fName = firstName;
            lName = lastName;
        }
    	}

    	class Program
    	{
        static void Main(string[] args)
        {
            //this is object
            Employee employee = new Employee();
            employee.SetName("John", "Grande");
            employee.Display();
        }
   	}
  1. What is a constructor, and what are its different types?

A constructor is like a method with the same name as the class, but it is a unique method. Even if it is not created, the compiler creates a default constructor in memory at the time of creating an object of the class.

The constructor is used to initialize the object with some default values.

Default constructor, parameterized constructor, copy constructor, static constructor, and private constructor are all different constructor types.

Below are examples of different constructor types.

public class Student
    	{
        private int rollNumber { get; set; }
        private string fullName { get; set; }

        //default constructor
        public Student()
        {
            //code goes here
        }

        //parameterized constructor
        public Student(int rNum, string fName)
        {
            this.rollNumber = rNum;
            this.fullName = fName;
        }

        //static constructor
        static Student()
        {
            //code goes here
        }

        //copy constructor
        public Student(Student student)
        {
            rollNumber = student.rollNumber;
            fullName = student.fullName;
        }
 }
  1. What is a destructor in C#?

A destructor clears out the memory to free up resources and is managed automatically by the garbage collector. System.GC.collect() is called internally for this purpose. However, if required, it can be done explicitly using a destructor.

public class Purchase
    	{
        //Syntax to write a destructor.
        ~Purchase()
        {
            //code here to release resources.
        }
}
  1. Is C# code managed or unmanaged code?

C# is managed code because Common Language Runtime compiles the code to intermediate language code.

  1. What are value types and reference types?

We can categorize variables into value type and reference type. Variables of value type contain the value directly while a reference type variable contains the reference of the memory address where the value is stored actually in the memory.

Bool, byte, int, char, and decimal are value types.

String, class, delegates are reference types.

Below is the pictorial representation of the value type.

Below is the pictorial representation of the reference type.

  1. What is a namespace and is it compulsory?

A namespace is a way of organizing classes of the same group or functionality under the same name. We can call it a module. Although it is not compulsory to put class in a namespace.

Refer to the syntax below.

namespace demoapp
{
    class SomeClass
    {
        public static void someMethod()
        {
            Console.WriteLine("Creating my namespace");
        }

    }
}
  1. Explain types of comments in C# with examples.

There are three types of comments in C#.

An example of a single-line comment is:

//Hey, this is a single line comment

An example of a multiline comment is:

/*This is a multiline comment

written in two lines2*/

An example of an XML comment is:

///Summary

///Here you can write anything

///summary

  1. Please explain encapsulation.

Encapsulation is a process of wrapping function and data members together in a class; it’s like a capsule, a single unit.

Encapsulation prevents an unauthorized or unwanted change of data from outside of the function.

Below is an example of encapsulation.

class User
    	{
        private string address;
        private string name;
        public string Address
        {
            get
            {
                return address;
            }
            set
            {
                address = value;
            }
        }
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }
    }
    class MyProgram
    {
        static void Main(string[] args)
        {
            User u = new User();
            // set accessor will invoke
            u.Name = "Ravi";
            // set accessor will invoke
            u.Address = "New Delhi";
            // get accessor will invoke
            Console.WriteLine("Name: " + u.Name);
            // get accessor will invoke
            Console.WriteLine("Location: " + u.Address);
            Console.WriteLine("\nPress Enter Key");
            Console.ReadLine();
        }
}
  1. What is an abstraction?

Abstraction is the method of exposing only the required features of the class and hiding unnecessary information.

We can try to understand it with the example of a motorbike:

A rider knows the color, name, and model of the bike. Still, they do not know the internal engine and exhaust functionality. Likewise, abstraction focuses on providing access for a specific functionality without exposing how that functionality works internally.

  1. What is polymorphism?

Polymorphism means the same method but different implementation. There are two types of polymorphism.

  1. Compile-time polymorphism is achieved by method overloading as seen in the example below. 
public class cellphone
    	{
        //function with the same name but different parameters.
        public void Typing()
        {
            Console.WriteLine("Using keypad");
        }

        public void Typing(bool isSmartPhone)
        {
            Console.WriteLine("Using qwerty keyboard");
        }
}
  1. Run time polymorphism is achieved by method overriding as seen in the example below. 
public class CellPhone
    	{
        public virtual void Typing()
        {
            Console.WriteLine("Using keypad");
        }
    	}

    	public class SmartPhone : CellPhone
    	{
        //method override
        public override void Typing()
        {
            Console.WriteLine("Typing function from child class");
        }
}
  1. Define an interface and show an example. 

An interface is another form of an abstract class that has only abstract public methods. These methods only have the declaration and not the definition. A class implementing the interface must have the implementation of all the methods of the interface.

For example:

interface IPencil
    	{
        void Write(string text);
        void Sharpen(string text);
    	}

    	class Pencil : IPencil
    	{
        public void Write(string text)
        {
            //some code here
        }

        public void Sharpen(string text)
        {
            //some code here
        }
    	}

    	public class CellPhone
    	{
        public virtual void Typing()
        {
            Console.WriteLine("Using keypad");
        }
}
  1. What is inheritance?

When we create a class that can inherit the data members and the methods of another class (parent class), it is called inheritance.

The class that inherits the properties and methods is called child class, derived class, or subclass. 

A class from which the child class inherits its properties and methods is a parent class or base class. 

Refer to the below example:

class Mobile  // base class (parent) 
    	{
        public void call()
        {
            Console.WriteLine("calling...!");
        }
    	}

    	class Nokia : Mobile  // derived class (child)
    	{
        public string modelName = "Nokia";
    	}

    	class MyProgram
    	{
        static void Main(string[] args)
        {
            // Create a myNokia object
            Nokia myNokia = new Nokia();

            // Calls the call() method (From the Mobile class) on the myNokia object
            myNokia.call();
        }
}

     class Nokia : Mobile  // derived class (child)

  1. How would you implement multiple interfaces with the same method name in the same class?

If we want to implement multiple interfaces with the same method name, then we cannot directly implement the body of the function. We have to explicitly provide the name of the interface to implement the body of the method. In this way, the compiler decides which interface methods we are referring to, and this resolves the issue.

This can be seen in the following example:

interface myInterface1
    	{
        void Print();
    	}
    	interface myInterface2
    	{
        void Print();
    	}
    	class Student : myInterface1,
        myInterface2
    	{
        void myInterface1.Print()
        {
            Console.WriteLine("For myInterface1 !!");
        }
        void myInterface2.Print()
        {
            Console.WriteLine("For myInterface2 !!");
        }
}
  1. What is the virtual method and how is it different from the abstract method?

A virtual method must have a default implementation, and we can override this virtual method using the override keyword in the derived class.

The abstract method is without implementation and is created inside the abstract class only. In the case of an abstract class, the class derived from the abstract class must have an implementation of that abstract method.

Here’s an example of virtual method:

public class CellPhone
    	{
        public virtual void Typing()
        {
            Console.WriteLine("Using old keypad");
        }
    	}

   	public class SmartPhone : CellPhone
    	{
        public override void Typing()
        {
            Console.WriteLine("Using qwerty keyboard");
        }
}

Here’s an example of an abstract method:

public abstract class CellPhones
    	{
        //no default implementation
        public abstract void Typing();
    	}

    	public class OldPhones : CellPhones
    	{
        //function override
        public override void Typing()
        {
            Console.WriteLine("Using keypad");
        }
    	}

    	public class SmartPhones : CellPhones
    	{
        //function override
        public override void Typing()
        {
            Console.WriteLine("Using Qwerty keyboard");
        }
}
  1. What is method overloading and method overriding?

Method overloading is when we have a function with the same name but a different signature.

Method overriding is when we override the virtual method of a base class in the child class using the override keyword.

Both method overloading and overriding are a type of polymorphism.

  1. What is the static keyword?

We use the static keyword to create a static class, a static method, or static properties.

When we create a static class there can be only static data members and static methods in that class.

Static means that we cannot create the instance of that class. That class can be used directly like ClassName.methodName.

When there is a need for special functions, which are typical for all the instances of other classes, then we use static class.

For example, there is a requirement to load some default application-level values. We create a static class with static functions. That class is then accessible to all other classes without creating any instance. It also shares the same data with all the classes.

Refer to the below example:

public static class Setting
    	{
        public static int fetchDefault()
        {
            int maxAmount = 0;
            //code to fetch and set the value from config or some file.
            return maxAmount;
        }
    	}

    	public class Sales
    	{
          //not required to create an instance.
          int maxAmount = Setting.fetchDefault();
}
  1. Can we use “this” with the static class?

No, we cannot use “this” with the static class because we can only use static variables and static methods in the static class.

  1. What is the difference between constants and read-only?

Constant variables have to be assigned a value at the time of declaration only and we cannot change the value of that variable throughout the program. 

We can assign the value to the read-only variable at the time of declaration or in a constructor of the same class.

Here is an example of constants:

using System;
namespace demoapp
{
    class DemoClass
    {
        // Constant fields 
        public const int myvar = 101;
        public const string str = "staticstring";

        // Main method 
        static public void Main()
        {
            // Display the value of Constant fields 
            Console.WriteLine("The value of myvar: {0}", myvar);
            Console.WriteLine("The value of str: {0}", str);
        }
    }
}

Here is an example of read-only:

using System;
namespace demoapp
{
    class MyClass
    {
        // readonly variables 
        public readonly int myvar1;
        public readonly int myvar2;

        // Values of the readonly 
        // variables are assigned 
        // Using constructor 
        public MyClass(int b, int c)
        {
            myvar1 = b;
            myvar2 = c;
            Console.WriteLine("Display value of myvar1 {0}, " +
             "and myvar2 {1}", myvar1, myvar2);
        }

        // Main method 
        static public void Main()
        {
            MyClass obj1 = new MyClass(100, 200);
        }
    }
}
  1. What is the difference between string and string builder in C#?

A string is an immutable object. When we have to do some actions to change a string or append a new string it clears out the old value of the string object, and it creates a new instance in memory to hold the new value in a string object. It uses System.String class, for example.

using System;
namespace demoapp
{
    class StringClass
    {
        public static void main(String[] {
            string val = "Hello";
            //creates a new instance of the string 
            val += "World";
            Console.WriteLine(val);
        }
    }
}

StringBuilder is a mutable object, meaning that it creates a new instance every time for the operations like adding string (append), replace string (replace). It uses the old object only for any of the operations done to the string and thus increases the performance. It uses System.Text.StringBuilder class, for example.

using System;
using System.Text;
namespace demoapp
{
    class StringClass
    {
        public static void main(String[] {
            StringBuilder val = new StringBuilder("Hello");
            val.Append("World");
            Console.WriteLine(val);
        }
    }
}

The output of both the program is the same, “Hello World.”

  1. Explain the “continue” and “break” statement.

We can use continue and break statements in a loop in C#. Using a break statement, we can break the loop execution, while using the continue statement, we can break one iteration of the loop.

Here’s an example of the break statement:

using System;
namespace demoapp
{
    class LoopingStatements
    {
        public static void main(String[] args)
        {
            for (int i = 0; i <= 5; i++)
            {
                if (i == 4)
                {
                    break; //this will break the loop
                }
                Console.WriteLine("The number is " + i);
                Console.ReadLine();
            }  //control will jump here after the break statement.
        }
    }
}

Here is the same example with a continue statement:

using System;
namespace demoapp
{
    class LoopingStatements
    {
        public static void main(String[] args)
        {
            for (int i = 0; i <= 5; i++)
            {
                if (i == 4)
                {
                    continue;// it will skip the single iteration
                }
                Console.WriteLine("The number is " + i);
                Console.ReadLine();
            }
        }
    }
}
  1. What are boxing and unboxing?

Conversion of value type datatype to reference type (object) datatype is called boxing.

For example:

namespace demoapp
{
    class Conversion
    {
        public void DoSomething()
        {
            int i = 10;
            object o = i;
        }
    }
}

Unboxing is the conversion of reference type datatype to value type.

For example: 

namespace demoapp
{
    class Conversion
    {
        public void DoSomething()
        {
            object o = 222;
            int i = (int)o;
        }
    }
}
  1. What is a sealed class?

We use a “sealed” keyword to create a sealed class. Classes are created as a sealed class when there is no need to inherit that further or when there is a need to restrict that class from being inherited.

Refer to the syntax below.

public sealed class MyClass
{
   //properties and methods
}
  1. What is a partial class?

There is a feature in the C# language to divide a single class file into multiple physical files. To achieve this, we have to use the “partial” keyword. At compile time, it is logically one file only; we cannot have a method with the same name or a variable with the same name in two different partial class files. 

Here, to facilitate the developers to break down the big class files into multiple small physical files, this feature is provided.

  1. What is enum?

In C# the “enum” keyword is used to declare an enumeration. An enum is a value type. It is a collection of related named constants referred to as an enumerator list. 

An enum type can be any of these (int, float, double, and byte). However, to use it beside int, explicitly casting is required.

To create a numeric constant in the .NET framework enum is used. All the members of the enum are of enum type, and there must be a numeric value for each enum type.

Int is the default type of the enumeration element. By default, the first enumerator has the value 0 and the value of each successive enumerator is then increased by 1.

Refer to the below syntax:

enum Day { Sat, Sun, Mon, Tue, Wed, Thu, Fri };

  1. What is dependency injection, and how can it be achieved?

Dependency injection is a design pattern. Instead of creating an object of a class in another class (dependent class) directly, we are passing the object as an argument in the constructor of the dependent class. It helps to write loosely coupled code and helps to make the code more modular and easy to test.

There are three ways to achieve dependency injection:

  1. Please explain the “using” statement.

The keyword “using” is used to define the scope of the resources used in that using statement block. All the resources used inside the using code block get disposed of once the code block completes execution.

Refer to the below example.

class Books : IDisposable
    	{
        private string _name { get; set; }
        private decimal _price { get; set; }

        public Books(string name, decimal price)
        {
            _name = name;
            _price = price;
        }

        public void Print()
        {
            Console.WriteLine("Book name is {0} and price is {1}", _name, _price);
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }
   	}

    	class Students
    	{
        public void DoSomething()
        {
            using (Books myBook = new Books("book name", 12.45))
            {
                myBook.Print();
            }
        }
}
  1. What are the access modifiers? Explain each type.

Access modifiers are keywords used to provide accessibility to a class, member, or a function.

Below are its types:

Syntax of access modifier:

public class Product
{
        public void Print()
        {
            //code to print something.
        }
}
  1. What are delegates?

Delegates are like function pointers, it is a reference data type that holds the reference of a method. We use delegates to write generic type-safe functions. All delegates derive from System.Delegate.

A delegate can be declared using the delegate keyword followed by a function signature, as shown below.

These are the characteristics of delegates:

Refer to the below example:

using System;
namespace demoapp
{
    class DelegateClass
    {
        // declare delegate
        public delegate void Print(int value);

        static void Main(string[] args)
        {
            // Print delegate points to PrintNumber
            Print printDel = PrintNumber;
            // or
            // Print printDel = new Print(PrintNumber);

            printDel(100000);
            printDel(200);

            // Print delegate points to PrintMoney
            printDel = PrintMoney;
            printDel(10000);
            printDel(200);
        }

        public static void PrintNumber(int num)
        {
            Console.WriteLine("Number: {0,-12:N0}", num);
        }

        public static void PrintMoney(int money)
        {
            Console.WriteLine("Money: {0:C}", money);
        }
    }
}
  1. What are the different types of delegates?

There are three types of delegates: 

  1. What is an array? Explain single and multi-dimensional arrays.

The array stores the value of the same type. It is a collection of variable stores into a memory location.

For example:

int[] marks = new int[3] { 25, 34, 89 };

A single-dimensional array is a linear array. Single-dimensional array stores variables in a single row. The above example is a single-dimensional array.

Arrays can have more than one dimension. Multi-dimensional arrays are also called rectangular arrays.

For example:

int[,] numbers = new int[3, 2] { { 1, 2 }, { 2, 3 }, { 3, 4 } };

  1. What is the difference between the System.Array.CopyTo() and System.Array.Clone() ?

Using the Clone() method, we can create a new array object containing all the elements of the original array and using the CopyTo() method. All the items of existing array copies into another existing array. Both ways create a shallow copy.

  1. What is the difference between array and ArrayList?

When we want to store the items of the same type, then the array is used. The array has a fixed size but not in the case of an ArrayList. We can store any type of data type in an ArrayList.

Refer to the example of an array and ArrayList:

using System.Collections;
namespace demoapp
{
    class Sample
    {
        //Array and Araraylist.
        public void ArrayFunction()
        {
            string[] country = new string[3];
            country[0] = "USA"; //only string value can be added
            country[1] = "Denmark";
            country[2] = "Russia";

            //can store different data types
            ArrayList arraylist = new ArrayList();
            arraylist.Add(3);
            arraylist.Add("USA");
            arraylist.Add(false);
        }
    }
}
  1. What is a jagged array in C#?

A jagged array is like a nested array where each element of a jagged array is an array in itself. The item of a jagged array can be of different dimensions and sizes.

A jagged array is a special type of array introduced in C#. A jagged array is an array of an array in which the length of each array index can differ.

Refer to the below example:

namespace demoapp
{
    public class JaggedArrayClass
    {
        public void ShowJaggedArray()
        {
            int[][] jaddedArray = new int[2][];

            jaddedArray[0] = new int[3] { 1, 2, 3 };

            jaddedArray[1] = new int[4] { 1, 2, 3, 4 };
        }
    }
}
  1. What is the difference between struct and class?

Class and struct are both user-defined but have significant differences.

A struct inherits from System.Value type, thus it’s a value type. Structs are preferable when there is a small amount of data. A structure cannot be abstract. There is no need to create an object with a new keyword. Struct does not have permission to create any default constructor.

Syntax of struct:

struct MyStruct
    	{
        public int MyProperty1 { get; set; }
        public int MyProperty2 { get; set; }
}

A class is a reference type in C#, and it inherits from the System.Object Type. When there is a large amount of data, classes are used. We can inherit one class from another class. A class can be an abstract type.

  1. What is the difference between “throw” and “throw ex”?

“Throw” statement holds the original error stack of the previous function or function hierarchy. In contrast, “throw ex” has the stack trace from the throw point.  It’s always advised to use “Throw” because it provides exact error information related to the function and gives you actual trace data of error source.

  1. Explain the difference between “finally” and “finalize block”?

Finally is a code block part of execution handling this code block executes irrespective of whether the exception occurs or not.

While the finalize method is called just before garbage collection. The compiler calls this method automatically when not called explicitly in code.

  1. Explain var and dynamic.

We can declare the var type of a variable without specifying the .net data types explicitly. The compiler automatically detects the type of a variable at the compile-time based on the value assigned to it. We cannot declare a var type variable without assigning a value to it. The value of the var type variable cannot be changed later in the code.

Dynamic is the opposite of var. We can change the value of a variable of type dynamic in the code later. It also decides the type of the variable based on the value assigned to it. 

Like at the time of creating a variable of type dynamic, a value of integer type is assigned to it, then also in the code further, we can assign a string type value to that variable. It holds the last changed value and acts like the data type of the latest values it holds.

Let us see the example to understand it in more detail.

public class Bike
    	{
        dynamic someValue = 21;

        public Bike()
        {
            //assigned string value later
            someValue = "Hello";
        }
}

In the above example, if we declare the variable “someValue” to type var instead of dynamic, it throws an error. The reason for that error is that in the next line, we changed the value of the variable and assigned a string value.

  1. What are Anonymous types in C#?

Anonymous types allow us to create new types without defining them. 

When there is a need to define read-only properties in a single object without defining each type. In that case, we use anonymous types. Here, a compiler generates type and is accessible only for the current block of code.

Refer to the below example.

public class SomeClass
    	{
     public void print()
     {
        var anonymousData = new
        {
             FirstName = "John",
             SurName = "lastname"
        };

       Console.WriteLine("First Name : " + anonymousData.FirstName);
     }
}
  1. What is multithreading, and what are its different states?

Any code block in C# runs in a process called a thread and it is the execution path of the program. Usually, an application runs in a single thread but multithreading helps to run the application in multiple threads. Using multithreading, we can divide the execution of our process among different threads to execute it simultaneously.

In multithreading, we can create multiple threads and assign particular tasks or put a code block to get executed. In this way, we can run more than one task at a time. This code block executes simultaneously and can save time, and in this way, we can make programs more efficient and fast.

Thread has its lifecycle, which includes various states of thread:

  1. How is exception handling done in C#?

Try, catch, finally, and throw — these are the keywords used to handle the exception.

Below is the explanation of each keyword:

Below is the example of exception handling:

public class SomeClass
    	{
    public void GetData()
    {
         try
         {
            //write some code here
         }
         catch (Exception)
         {
             throw;
         }
         finally
         {
            /*code to execute in the last
            like dispose objects and resource*/
         }
    }
 }
  1. What are custom exceptions?

Sometimes some errors need to be caught as per user requirements. Custom exceptions are used in this instance and are user-defined exceptions.

Refer to the below example:

public class Purchase
{
     public void DoPurchase(int quantity)
     {
         if (quantity == 0)
         {
             //this will throw error here with the custom message
             throw new Exception("Quantity cannot be zero");
         }
     }
}
  1. What is LINQ in C#?

Language integrated query is the full form of LINQ. It is a method of querying data using the .net capabilities and C# syntax similar to SQL query.

The advantage of LINQ is that we can query different sources of data. The data source could be either collection of objects, XML files, JSON files, In-memory data or lists or, database objects. We can easily retrieve data from any object that implements the IEnumerable<T> interface.

Below is the syntax of LINQ.

public class Devices
    	{
           public void GetData()
           {
            List<string> mobiles = new List<string>() {
                "Iphone","Samsung","Nokia","MI"
            };

            //linq syntax
            var result = from s in mobiles
                         where s.Contains("Nokia")
                         select s;

           }
}	
  1. What is serialization?

When we want to send an object through a network, then we have to convert that object into a stream of bytes. Serialization is the process of converting an object into a stream of bytes. To facilitate the object for serializable, it should implement ISerialize Interface. The process of de-serialization is the reverse process of creating an object from a stream of bytes. 

  1. What are generics in C#?

Generics increase performance, increase type safety, reduce repeated code, and makes reusable code. Using generics, we can create collection classes. It is preferred to use System.Collections.Generic namespace instead of classes such as ArrayList in the System.Collections namespace to create a generic collection.

Generics encourage the usage of parameterized types as seen in the example below:

using System;
namespace demoapp
{
    //We use < > to specify Parameter type 
    public class GFG<T>
    {
        //private data members 
        private T data;

        //using properties 
        public T value
        {
            /using accessors 
            get
            {
                return this.data;
            }
            set
            {
                this.data = value;
            }
        }
    }

    //vehicle class 
    class Vehicle
    {
        //Main method 
        static void Main(string[] args)
        {
            //instance of string type 
            GFG<string> company = new GFG<string>();
            company.value = "Tata motors";

            //instance of float type 
            GFG<float> version = new GFG<float>();
            version.value = 6.0F;

            //display Tata motors 
            Console.WriteLine(company.value);

            //display 6 
            Console.WriteLine(version.value);
        }
    }
}
  1. What is reflection?

Reflection is a particular class in C# used to access the metadata of the assembly or the class.

The following information can be retrieved using reflection:

  1. How to use nullable types?

In C#, we can also assign a null value to the variable. Such types are called nullable types.

Example below:

namespace demoapp
{
    class Calculate
    {
        int? number = null;
        public Calculate(int num)
        {
            number = num;
        }

        public void DoCalculation()
        {
            if (number.HasValue)
            {
               //do something
            }
        }
    }
}
  1. Which is the parent class of all classes which we create in C#?

System.object.

  1. Explain code compilation in C#.

The C# compiler compiles the code into managed code, also called bytecode. Then, the JIT (Just in Time compiler) compiles the bytecode into native or machine language, which is directly executed by CPU.

Referring to the above questions and answers gives us in-depth knowledge of all essential concepts of C# language. These technical answers can help to sharpen our knowledge and helps to increase our comprehension of the language.

Top courses in C#

C# .NET For Beginners
Rick Phillips
4.5 (1,262)
Complete C# Unity Game Developer 3D
Ben Tristem, Rick Davidson, GameDev.tv Team
4.7 (26,637)
Bestseller
C# Intermediate: Classes, Interfaces and OOP
Mosh Hamedani
4.5 (23,000)
Bestseller
RPG Core Combat Creator: Learn Intermediate Unity C# Coding
Ben Tristem, Rick Davidson, Sam Pattuzzi, GameDev.tv Team
4.7 (8,445)
Complete C# Masterclass
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.5 (11,836)
Design Patterns in C# and .NET
Dmitri Nesteruk
4.4 (7,049)
Bestseller
How to Program Voxel Worlds Like Minecraft with C# in Unity
Penny de Byl, Penny @Holistic3D.com
4.6 (1,408)
RPG Inventory Systems: Intermediate C# Game Coding Course
Sam Pattuzzi, GameDev.tv Team, Rick Davidson
4.3 (386)

More C# Courses

C# students also learn

Empower your team. Lead the industry.

Get a subscription to a library of online courses and digital learning tools for your organization with Udemy for Business.

Request a demo

Courses by Denis Panjuta

Der Unity 2017 & Blender Komplettkurs: Erstelle Top 3D Games
Denis Panjuta, Jannick Leismann, Tutorials.eu by Denis Panjuta
3.7 (492)
Online Course Creation Masterclass - Udemy - Unofficial
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.3 (18)
Complete C# Unity Developer: Create Games and Learn to Code
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.4 (865)
Xamarin Forms: Erstelle Native Cross Plattform Apps mit C#
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.1 (312)
Bestseller
Erstelle iOS Apps die geliebt werden
Codestars by Rob Percival, Denis Panjuta, Rob Percival, Tutorials.eu by Denis Panjuta
4 (746)
Erstelle einen 3D Jump and Run Plattformer mit Unity 3D
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.4 (42)
Lerne großartige Webseiten zu erstellen
Jannis Seemann, Jan Brinkmann, Denis Panjuta, Jannis Seemann (CodingCourses.TV), Tutorials.eu by Denis Panjuta
4.3 (717)
Der ultimative Wordpress Kurs- dein Weg zur eigenen Webseite
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.6 (32)
JavaScript und jQuery für Beginner
Denis Panjuta, Tutorials.eu by Denis Panjuta
3.7 (146)
Erstelle Android Apps, die geliebt werden!
Denis Panjuta, Codestars by Rob Percival, Tutorials.eu by Denis Panjuta
4.6 (893)
Highest Rated
Online Geld verdienen - Lebensunterhalt mit Videokursen
Denis Panjuta, Tutorials.eu by Denis Panjuta
4.2 (154)
Der Komplette Web-Entwickler Kurs - Erstelle 14 Webseiten
Denis Panjuta, Codestars by Rob Percival, Tutorials.eu by Denis Panjuta
4.3 (658)

Courses by Denis Panjuta