A list of top frequently asked C# interview questions and Answers for Freshers and 2 - 4 years Experienced Dot Net developers and Testers with sample code and best answers are given below.
Where, scores is an array of two arrays of integers - scores[0] is an array of 3 integers and scores[1] is an array of 4 integers.
Unboxing: is the process of converting an object type to a value type.
1) What is C#?
C# is a modern, general-purpose, object-oriented programming language developed by Microsoft. It is a safe and managed language that is compiled by .NET framework to generate Microsoft intermediate language(IL) (machine code).2) What are the main reasons to use C# language?
- 1. Easy to learn
- 2. Part of .NET framework
- 3. General purpose and object oriented programming language
- 4. Component oriented
- 5. Structured language
- 6. Can be compiled on variety of computer platforms
- 7. Produces efficient programs
3) What are the features of C#?
- 1. Constructors and Destructors
- 2. Properties
- 3. Passing Parameters
- 4. Arrays
- 5. Main
- 6. XML Documentation and
- 7. Indexers
4) What are Integrated Development Environment (IDE)'s provided by Microsoft for C# development?
- 1. Visual Studio Express (VCE)
- 2. Visual Studio (VS)
- 3. Visual Web Developer
5. What is Access Specifiers in C#?
Access Specifiers defines the scope of a class member. A class member can be variable or function. In C# there are five types of access specifiers are available.- * Public : public is the most common access specifier in C# . It can be access from anywhere, that means there is no restriction on accessibility. The scope of the accessibility is inside class as well as outside.
- * Private : The scope of the accessibility is limited only inside the classes or struct in which they are declared.
- * Protected : The scope of accessibility is limited within the class or struct and the class derived (Inherited )from this class.
- * Internal : The internal access modifiers can access within the program that contain its declarations and also access within the same assembly level but not from another assembly.
- * Protected Internal : Protected internal is the same access levels of both protected and internal. It can access anywhere in the same assembly and in the same class also the classes inherited from the same class.
6) Explain namespaces in C#?
The namespace keyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types. “Using” keyword can be used for using the namespace in other namespace. Declaration of Namespaces: using System; using System.Data;7) Why to use “using” in C#?
“Using” statement calls – “dispose” method internally, whenever any exception occurred in any method call and in “Using” statement objects are read only and cannot be reassignable or modifiable.8) Explain the types of comments in C#?
Below are the types of comments in C# -- 1. Single Line Comment Eg : //
- 2. Multiline Comments Eg: /* */
- 3. XML Comments Eg : ///
9) What is the difference between public, static and void?
You can access public declared variables anywhere in the application. Static declared variables are globally accessible without creating an instance of the class. Void is a type modifier that specifies that the method doesn't return any value.10) What is Jagged Array in C#?
A Jagged Array is an array of an array in which the length of each array index can differ. You can initialize a jagged array as −int[][] scores = new int[2][]{new int[]{92,93,94},new int[]{85,66,87,88}};
11) What is constructor in C#?
A constructor is a member function in the class and has the same name as its class. Whenever the object class is created, the constructor is automatically invoked. It constructs the value of data members while initializing the class.12) What are the different types of constructors in C#?
Basically, there are five types of constructors:- 1. Static constructor
- 2. Private constructor
- 3. Copy constructor
- 4. Default constructor
- 5. Parameterized constructor
13) What is static constructor?
Static constructor is used to initialize static data members as soon as the class is referenced first time, whereas an instance constructor is used to create an instance of that class with keyword. A static constructor does not take access modifiers or have parameters and can't access any non-static data member of a class.14) In how many ways you can pass parameters to a method?
There are three ways that parameters can be passed to a method −- Value parameters - This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.
- Reference parameters - This method copies the reference to the memory location of an argument into the formal parameter. This means that changes made to the parameter affect the argument.
- Output parameters - This method helps in returning more than one value.
15. What is Boxing and Unboxing?
Boxing: is the process of converting a value type data type to the object or to any interface data type which is implemented by this value type.Unboxing: is the process of converting an object type to a value type.
No comments:
Post a Comment