C# Programming

Created by zbzzt Plus

Upgrade to
remove ads

95 terms · Set of interview questions and general info about C# programming

What is C#

General purpose, type safe, object oriented, platform neutral programming language. Works best with the windows .Net framework and is the most up to date Visual Studio language

What does the 2.0 version of C# include and when was it released?

The 2.0 version of C# includes such new features as generics, partial classes, and iterators and was released in late 2005.

What is the .NET Framework?

a software framework developed by Microsoft that runs primarily on Microsoft Windows. It includes a large library and provides language interoperability (each language can use code written in other languages) across several programming languages. Programs written for the .NET Framework execute in a software environment (as contrasted to hardware environment), known as the Common Language Runtime (CLR), an application virtual machine that provides important services such as security, memory management, and exception handling. The class library and the CLR together constitute the .NET Framework.

What is the CLR?

Common Language Runtime: the virtual machine component of Microsoft's .NET framework and is responsible for managing the execution of .NET programs. In a process known as just-in-time (JIT) compilation, the CLR compiles the intermediate language code known as Common Intermediate Language (CIL) into the machine instructions that in turn are executed by the computer's CPU. The CLR provides additional services including memory management, type safety and exception handling. All programs written for the .NET framework, regardless of programming language, are executed by the CLR. It provides exception handling, Garbage collection and thread management.

Does C# support multiple-inheritance?

No. C# limits classes to single-inheritance, meaning each classes inherit from a single parent class. This is done to prevent ambiguity.

What is JIT (just in time compiling)?

a method to improve the runtime performance of computer programs. JIT compilers represent a hybrid approach, translation occurring continuously, as with interpreters, but with caching of translated code to minimize performance degradation. also offers other advantages over statically compiled code at development time, such as handling of late-bound data types and the ability to enforce security guarantees. JIT builds upon two earlier ideas in run-time environments: bytecode compilation and dynamic compilation. It converts code at runtime prior to executing it natively, for example bytecode into native machine code.

What is the goal of JIT?

to reach or surpass the performance of static compilation, while maintaining the advantages of bytecode interpretation: Much of the "heavy lifting" of parsing the original source code and performing basic optimization is often handled at compile time, prior to deployment: compilation from bytecode to machine code is much faster than compiling from source.

What are the 5 visibility levels (access modifiers)?

1) public: available to anyone anywhere
2) protected: can be accessed by the class itself and by any class derived from that class
3) internal: accessible only in the same assembly and invisible outside it.
4) protected internal: available to classes that are within the same assembly and derived from the specified base class.
5) private: only the class or struct declaring the member is allowed access to that member.

Are private class-level variables inherited?

Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.

What is the top .NET class that everything is derived from?


What does the term immutable mean?

The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.

What is the different between System.String and System.Text.StringBuilder classes?

System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

Whats the advantage of using System.Text.StringBuilder over System.String?

StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable so each time a string is changed, a new instance is created in memory.

Can you store multiple data types in System.Array?


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

The Clone() method returns a new array object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy.

What is the difference between a shallow copy and a deep copy?

A shallow copy means that the contents (each array item) contains references to the same object as the elements in the original array. A deep copy would create a new instance of each element's object, resulting in a different, yet identical object.

How can you sort the elements of an array in descending order?

By calling the Sort() and then Reverse() methods.

What is the .NET collection class that allows an element to be accessed using a unique key?


What class is optimized for key-based item retrieval from small collections?


What is the C# syntax to catch any possible exception?

a catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch{}.

Explain how a finally block works.

A try/catch block can be optionally followed by a finally block that will be executed whether or not the code in the try or catch blocks executes successfully.

Can multiple catch blocks be executed for a single try statement?

No. Once the proper catch block is executed, control is passed to the finally block (if there is any).

Explain the three services model commonly known as a three-tier application.

1) Presentation (UI)
2) Business (logic and underlying code)
3) Data (from storage or other sources).

Can you prevent your class from being inherited by another class?

Yes. The keyword "sealed" will prevent the class from being inherited.

Can you allow a class to be inherited, but prevent a method from being overridden?

Yes. Just leave the class public and make the method sealed.

What is an abstract class?

A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is basically a blueprint for a class without any implementation.

When do you absolutely have to declare a class as abstract?

1) When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
2) When at least one of the methods in the class is abstract.

What is an interface?

Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes. it purely represents a contract between an object and a user of the object. An interface cannot be directly instantiated as an object. No data members can be defined in an interface.

What is the difference between an interface and an abstract class?

In an interface class, all methods are abstract, there is no implementation at all. In an abstract class, some methods can be concrete. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers.

Can you specify the accessibility modifier for methods inside of an interface?

No. All methods must be public.

Can you inherit multiple interfaces?

Yes, .NET supports multiple interface inheritance.

What is the difference between a struct and a class?

Structs are value-type variables and are thus saved on the stack, additional overhead, but faster retrieval. Also structs cannot inherit.

What is the implicit name of the parameter that gets passed into the set method/property of a class?

The data type of the "value" parameter is defined by whatever data type the property is declared as.

What does the keyword "virtual" declare for a method or property?

The method or property can be overridden and most importantly, the run-time type of the object determines which method is to be invoked.

Can you declare an override method to be static if the original method is not static?

No. The signature of the virtual method must remain the same. Only the keyword virtual is replaced by the keyword override.

What are the different ways a method can be overloaded?

A method can be overloaded with different parameter types, a different number of parameters, and different order of parameters.

If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class. For example, public MyDerivedClass (int y) : base (y+1) where the parent class has a constructor that takes an int as a parameter.

What is a delegate?

a form of type-safe function pointer used by the .NET Framework. Delegates specify a method to call and optionally an object to call the method on. They are used, among other things, to implement callbacks and event listeners. Delegates form the basis of event handling.

What is a multicast delegate?

a delegate that points to several methods. Multicast delegation is a mechanism that provides functionality to execute more than one method. There is a list of delegates maintained internally, and when the multicast delegate is invoked, the list of delegates is executed.

What is the difference between //, /**/, and /// comments?

// is for single-line comments, /**/ is for multi-line comments, and /// is for XML documentation comments

How do you generate documentation from the C# file commented properly with a command-line compiler?

Compile it with the /doc switch.

What debugging tools come with the .NET SDK?

1) CorDBG - command-line debugger. You must compile the original C# file using the /debug switch to use CorDBG. 2) DbgCLR - graphic debugger. Visual Studio .NET uses the DbgCLR.

What does the assert() method do?

In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.

What is the difference between the Debug class and Trace class?

Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

Why are there five tracing levels in System.Diagnostics.TraceSwitcher?

The tracing dumps can be quite verbose. For applications that are constantly running, you run the risk of overloading the machine and the hard-drive. Five levels range from None to Verbose, allowing you to fine-tune tracing activities.

What are the three test cases you should go through in unit testing?

1) Positive test cases (correct data, correct output).
2) Negative test cases (broken or missing data, proper handling).
3) Exception test cases (exceptions are thrown and caught properly).

Can you change the value of a variable while debugging a C# application?

Yes. If you are debugging via Visual Studio .NET, you can do this through the Immediate Window.

Explain ACID rule of thumb for transactions.

A transaction must be:
1) Atomic - it is one unit of work and does not depend on previous and following transactions.
2) Consistent - data is either committed or rolled back, no "in-between" case where something has been updated and something hasn't.
3) Isolated - no transaction sees the intermediate results of the current transaction.
4) Durable - the values persist if the data has been committed even if the system crashes right after.

Between Windows Authentication and SQL Server Authentication, which one is trusted and which one is untrusted?

Windows Authentication is trusted because the username and password are checked with Active Directory. The SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.

What does the Dispose() method do with the connection object?

Closes the connection and deletes the object from memory.

What is a pre-requisite for connection pooling?

Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings. The connection string must be identical.

How is the DLL Hell problem solved in .NET?

Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32) but also the version of the assembly.

What are the ways to deploy an assembly?

An MSI installer, a CAB archive, and XCOPY command.

What is a satellite assembly?

When you write a multilingual or multicultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

What namespaces are necessary to create a localized application?

System.Globalization and System.Resources.

What is the smallest unit of execution in .NET?

an assembly.

When should you call the garbage collector in .NET?

As a good rule, you should not call the garbage collector. However, you could call the garbage collector when you are done using a large object (or sets of objects) to force the garbage collector to dispose of those very large objects from memory. This is usually not good practice.

How do you convert a value-type to a reference-type?

Use boxing.

What happens in memory when you box and unbox a value-type?

Boxing converts a value-type to a reference-type, thus storing the object on the heap. Unboxing converts a reference-type to a value-type, thus storing the value on the stack.


Compilation of classes. In C# Usually ends in .dll or .exe


Block of memory where objects live. Whenever a new object is created it is allowed onto the heap. Old objects are regularly deallocate from the heap to save available memory


Block of memory for storing local variables and parameters. Automatically grows and shrinks as function is entered and excited.


Names reserved by the compiler that coders are not allowed to use as identifiers. Keywords are also already identifiers themselves.


Groups classes together so that they have a unique identifier


Encapsulation is the process of providing access to an object only through it's messages while keeping the details private. Encapsulation controls the use of a class.

Primitive data type

Built into C#. Built into the XML Schema. In C# primitive data types are all objects in the system namespace. Most common are: Int, Long, Float, Double, Decimal, String, Char and Bool.

Unary operator

Only requires one operand, usually a count+1 or a count++ or a count--

What is reflection?

provides objects (of type Type) that describe assemblies, modules and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties. If you are using attributes in your code, reflection enables you to access them.

When is reflection useful?

1) When you have to access attributes in your program's metadata.
2) For examining and instantiating types in an assembly
3) For building new types at runtime.
4) For performing late binding, accessing methods on types created at run time

What is bitwise AND?

takes two binary representations of equal length and performs the logical AND operation on each pair of corresponding bits. The result in each position is 1 if the first bit is 1 and the second bit is 1; otherwise, the result is 0

What is bitwise OR?

takes two bit patterns of equal length and performs the logical inclusive OR operation on each pair of corresponding bits. The result in each position is 1 if the first bit is 1 or the second bit is 1 or both bits are 1

What is bitwise NOT?

a unary operation that performs logical negation on each bit, forming the ones' complement of the given binary value. Bits that are 0 become 1, and those that are 1 become 0.

What is bitwise XOR?

takes two bit patterns of equal length and performs the logical exclusive OR operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1

What is bitwise LEFT shifting?

The binary operator << evaluates its operands and returns the resulting first argument left-shifted by the number of bits specified by the second argument. It discards high-order bits that shift beyond the size of its first argument and sets new low-order bits to zero.

What is bitwise RIGHT shifting?

The binary operator >> evaluates its operands and returns the resulting first argument right-shifted by the number of bits specified by the second argument. It discards low-order bits that are shifted beyond the size of its first argument and sets new high-order bits to the sign bit of the first argument, or to zero if the first argument is unsigned.

What does the yield keyword mean?

A yield statement is used to create an iterator, i.e. a function that returns a sequence of values from an object implementing IEnumerable. Instead of using return to return the sequence, you use yield return to return individual values and yield break to end the sequence.

What is polymorphism?

a programming language feature that allows values of different data types to be handled using a uniform interface. The concept of parametric polymorphism applies to both data types and functions. A function that can evaluate to or be applied to values of different types is known as a polymorphic function. A data type that can appear to be of a generalized type (e.g., a list with elements of arbitrary type) is designated polymorphic data type like the generalized type from which such specializations are made.

What does mutex mean?

stands for mutual exclusion: refers to the problem of ensuring that no two processes or threads (henceforth referred to only as processes) can be in their critical section at the same time. Here, a critical section refers to a period of time when the process accesses a shared resource, such as shared memory.

What is a "using" statement?

defines a scope at the end of which an object will be disposed. The object you instantiate must implement the System.IDisposable interface.

What are class properties?

class members that expose functionality of methods using the syntax of fields. They simplify the syntax of calling traditional get and set methods (a.k.a. accessor methods). Like methods, they can be static or instance.

What are indexers?

are class members that define the behavior of the array access operation (e.g. list[0] to access the first element of list even when list is not an array). To create an indexer, use the this keyword as in the following

public string this[string key]
get {return coll[_key];}
set {coll[_key] = value;}

What is the Singleton Pattern?

a design pattern that restricts the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects. The terms comes from the mathematical concept of a singleton.

What is an event?

a special kind of delegate that facilitates event-driven programming. Events are class members which cannot be called outside of the class regardless of its access specifier. So, for example, an event declared to be public would allow other classes the use of += and -= on the event, but firing the event (i.e. invoking the delegate) is only allowed in the class containing the event.

What are partial classes?

class definitions can be split up across multiple physical files. To the compiler, this does not make a difference as all the fragments of the partial class are grouped and the compiler treats it as a single class.

What are generics?

they are classes, structures, interfaces, and methods that have placeholders (type parameters) for one or more of the types that they store or use. they let you tailor a method, class, structure, or interface to the precise data type it acts upon. most frequently used with collections and the methods. can also create custom generic types and methods to provide your own generalized solutions and design patterns.

What are predicates?

A predicate is a function that returns true or false. a predicate delegate is a reference to a predicate. a predicate delegate is a reference to a function that returns true or false. Predicates are very useful for filtering a list of values.

What is func?

Func<T0,bool> is the same as a System.Predicate<T> delegate. Same as predicate but takes one parameter (still returns true or false).

What are lambdas?

Lambda expressions provide a concise way to write first-class anonymous function values.
ex: listOfFoo.Where(x => x.Size > 10);
lambda expressions are merely short-hand syntax for anonymous delegates with type inference for parameters and return type

What are Extension methods?

Extension methods are a form of syntactic sugar providing the illusion of adding new methods to the existing class outside its definition. In practice, an extension method is a static method that is callable as if it was an instance method; the receiver of the call is bound to the first parameter of the method, decorated with keyword this. Extension methods allow developers to add new methods to the public contract of an existing CLR type, without having to sub-class it or recompile the original type.

What are the three things necessary for creating extension methods?

1. All Extension Methods need to be defined in a static class.
2. All Extension Methods need to be defined as a static method.
3. All Extension Methods need to take at least one parameter defined as follows:
this (keyword) string (type) parameterName

What are mock objects?

In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the dynamic behavior of a human in vehicle impacts.

What is the significance of Application.Idle?

it's how message processing is done on the application's UI thread; has become a convenient place to take care of application housekeeping chores asynchronously within the primary operations of the app without getting involved with multiple threads; menus and buttons are typically enabled or disabled to match their corresponding command states when the application goes idle

What is a constraint?

When you define a generic class, you can apply restrictions to the kinds of types that client code can use for type arguments when it instantiates your class. If client code tries to instantiate your class by using a type that is not allowed by a constraint, the result is a compile-time error. Constraints are specified by using the where contextual keyword.

What is the significance of the "where" keyword?

public abstract class ObjectMapperBase<T> where T : new()
internal abstract bool UpdateObject(T plainObjectOrginal, T plainObjectNew, WebMethod fwm, IDbTransaction transaction);

The "new()" constraint tells the compiler that all objects of type T must have a public parameterless constructor

What are the different permutations of how to use the "where" keyword?

1) where T: struct
2) where T : class
3) where T : new()
4) where T : <base class name>
5) where T : <interface name>
6) where T : U

Please allow access to your computer’s microphone to use Voice Recording.

Having trouble? Click here for help.

We can’t access your microphone!

Click the icon above to update your browser permissions above and try again


Reload the page to try again!


Press Cmd-0 to reset your zoom

Press Ctrl-0 to reset your zoom

It looks like your browser might be zoomed in or out. Your browser needs to be zoomed to a normal size to record audio.

Please upgrade Flash or install Chrome
to use Voice Recording.

For more help, see our troubleshooting page.

Your microphone is muted

For help fixing this issue, see this FAQ.

Star this term

You can study starred terms together

NEW! Voice Recording

Create Set