C#.NET Interview Questions and Answers – Part 1

Published on March 11, 2015 by abundantcode

Filed under Interview Questions

Last modified March 12, 2015

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3204 times

C#.NET Interview Questions and Answers – Part 1

1. What is an Assembly in .NET?

An assembly is a unit of deployment in .NET. The assembly can either be an exe file or a dll (library).

When there is an entry point for the assembly, then it’s an exe else it is a dll file. The advantage of the dll is that it can be consumed by the other libraries or the application.

2. What is a Name of the C# Compiler?

The name of the C# compiler in .NET is csc.exe. There are 2 ways in which you can call the C# compiler.

1. From Visual Studio

2. Command Line

3. How to compile the C# Program from Command line?

The Developers can call the C# compiler to compile the programs manually from the command line.

Follow the below steps to compile C# program from Command line.

1. Open Notepad and start writing your first C# Program and save it as AC1.cs. Set the path to the folder where the AC1.cs file is stored.

2. Open Visual Studio Command Prompt and type the command as follows

csc E:\AC1.cs

3. When the above command is executed, the C# compiler will provide an application with the name AC1.exe in the same folder where AC1.cs is found.

4. How to generate a dll file from Command Line in C#?

Follow the below steps to generate a dll file from Command Line in C#.

1. Open Notepad and start writing your first C# Program and save it as AC1.cs. Set the path to the folder where the AC1.cs file is stored.

5. Open Visual Studio Command Prompt and type the command as follows

csc /target:library /out:E:\CS\AC1.dll E:\Cs\AC1.cs

6. When the above command is executed, the C# compiler will provide a library with the name AC1.dll in the same folder where AC1.cs is found.

5. Can you use an Identifier with the same name as Keyword in C#?

In C#, if you want to use an identifier with the same name as keyword, you can do it by prefixing the name with the @ symbol.

For example

String @string is a valid identifier in C#

This can be a useful feature when using the third party library written in a different language that conflicts with the keyword in C#.

6. What are Contextual Keywords in C#?

Contextual keywords are keywords in C# which can also be used as identifiers without the @symbol.

Some of the examples of contextual keywords include dynamic, partial, where, select etc.

7. Is Date Time, a predefined type in C#?

No, the DateTime type in not predefined by C#. An Interesting read on why DateTime is not a predefined type in c# can be found at http://stackoverflow.com/questions/10058883/why-is-there-no-date-shorthand-of-system-datetime-in-c/10063923#10063923

8. What is a Static Member?

The Data members and functions that does not operate on the instance of the type but rather than on type is a static member. These members are marked with the keyword static.

Eg: Console class is a static class where all its members are marked as static. To access the members of the Console Class, you don’t create an instance of the Console class since this class is shared across the whole application.

9. What are Implicit Conversion and Explicit Conversion in C#?

The Conversion between compatible types are easily possible in c#. There are 2 types of conversion possible in C# for the compatible types.

1. Implicit – Which happens automatically. Eg : int to long conversion

2. Explicit – Requires a casting. Eg : int to short conversion.

int a = 1;

long b = a; // Implicit conversion

short c = (short) a; // Explicit conversion

10. What are the different Types in C#?

The different Types supported in C# includes

1. Value Types – This includes numeric types , char , struct,enum and bool.

2. Reference Types – This includes classes , array , delegate etc.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to convert List<string> to string with comma delimiter in C# ?

If you need to convert a collection (for example List of string) to string separated with the Comma ...

Microsoft announces Visual Studio Code with support for Linux and Mac OS X

Looks like a good time for the .NET Developers for developing on not just on Windows platform but al...

What is XAML?

What is XAML? XAML is a language from Microsoft which stands for eXtensible Application Markup Lang...