Skip to main content

C#.NET INTERVIEW QUESTIONS


1)what is CLR?
CLR is the virtual machine component of Microsoft's .NET framework which is used for memory management and debugging.
2)what is CTS?
CTS is common type system which is used to provide common datatypes for all .net supportable languages.
3)what is Nullable datatypes?
Nullable datatypes are used to assign a null value for integer
int? a = null;
Console.WriteLine(a);
Nullable datatypes are introduced from .net 2.0 and above versions
4)what is the default datatype to store integer value?
int
5)what is the default datatype to store decimal value?
double
6)what is the Difference between ToString() and Convert.ToString()?
ToString() doesnot handle null values
Convert.ToString()will handle null values.
string s = null;
// string s1 = s.ToString();
string s2 = Convert.ToString(s);
Console.WriteLine(s2);
7)what is the Difference between int.Parse() and Convert.ToInt32()?
int.Parse() is used to convert string to int
Convert.ToInt32() is used to convert any datatype to int
8)what is the difference between Valuetype datatype
Value type Reference type
Value type they are stored on stack
Value type store real data .
Value types are faster in access
Value type consists of primitive data types, structures, enumerations.
Value types derive from System.ValueType
Value types can not contain the value null.
========================================================================
Reference type they are stored on heap
Reference type store reference to the data
Reference types are slower in access.
Reference type consists of class, array, interface, delegates
Reference types derive from System.Object
Reference types can contain the value null.
========================================================================
9) what is the checked block and unchecked block?
checked block is used to enable overflow checking for arthimetic and conversion functions.
Ex:- byte b=255;
b++;
C.WL(b);
o/p:- 0 because the range of byte is 0-255 so if the range is exceeded then the value of byte will round to 0 but this type of programming is not safe so if the range of byte is exceeded then runtime error must occur so we have to go for checked block.
checked
{
byte b=255;
b++;
C.WL(b);
}
o/p:- A runtime error will occur saying that
Arithmetic operation resulted in an overflow.
10)wap to get the range of byte?
C.WL(byte.MinValue);
C.WL(byte.MaxValue);
11)what is the difference between typeOf() and sizeOf()?
typeOf() will get the base(CTS) datatype name
sizeOf() will get the size of the datatype
Console.WriteLine(typeof(byte));
Console.WriteLine(sizeof(byte));
12. what is the Difference between Boxing and UnBoxing?
Boxing is a process of converting value type datatype to Reference type Datatype
UnBoxing is a process of converting reference type datatype to value type datatype
13. what is widening and Narrowing?
widening:- it is a process of converting smaller datatype to longer datatype
Ex:- byte-------int
int---------long
int i=10;
long l;
l=i;
C.WL(l);
Widening does not require Explicit Type casting
Narraowing:- it is a process of converting longer datatype to smaller datatype
Narrowing is unsafe type of programming because the data accuracy is not maintained.
while working with Narrowing we have to do Explicit Type casting
long l=10;
int i;
i=(int)l;
14)what is the difference between string and stringbuilder?
Both string and StringBuilder are classes.
string is immutable and stringbuilder is mutable
immutable means the value will not change
mutable means the value will change
string will allocate a new memory whenever we concadinate the string value but stringbuilder class will have a method Append() this method is used to insert the new value on the existing value.
so the usage of stringbuilder is more efficient in case of large amount of string
manipulations
if 100% of memory was alocated for a project then98% of memory will be occupied by string
but stringbuilder will occupy nearly 28% of memory so performance wise stringbuilder is more efficient than string
Ex:- string s = "saurav";
Console.WriteLine(s.GetHashCode());
s = s + "Technologies";
Console.WriteLine(s.GetHashCode());
s = s + 10;
Console.WriteLine(s.GetHashCode());
Console.WriteLine("====================");
StringBuilder s1 = new StringBuilder("saurav");
Console.WriteLine(s1.GetHashCode());
s1.Append("technologies");
Console.WriteLine(s1.GetHashCode());
s1.Append("10");
Console.WriteLine(s1.GetHashCode());
Ex for string
class Program
{ static void Main()
{ string x = "";
for (int i = 0; i < 2; i++)
{ x = "saurav" + x;
C.WL(x); C.WL(x.GetHashCode()); } } }
Ex for string Builder
StringBuilder x =new StringBuilder();
for (int i = 0; i < 2; i++)
{ x.Append("sathya" + x);
Console.WriteLine(x);
Console.WriteLine(x.GetHashCode()); }
15)what is an Assembly?
Assembly is the compiled format of any .net program which may be .dll or .exe
16)How to view an Assembly?
goto--->start--->MSVS2010---->MSVS2010--->
Visual studio Tools--->
Visualstudiocommandprompt----->ILDASM.exe
IntermediateLangiageDisAssembler
17)what is the difference between Private assembly and public assembly?
Private assembly:- The assembly that was specific for a single application is called as
private assembly or folder specific assembly
A seperate copy of dll will be copied in each and every location where we consumed the dll.
Public Assembly: The Assembly that was registered under GAC is called as Public Assembly
while working with public a single copy of dll will be maintained under GAC Location.
18)what is GAC?
Global Assembly Cache
19)what is Reflection?
Reflection is used to get the information about an assembly programatically by writing some code
20)How to implement Reflection in .net?
by using System.Reflection
System.Type
21)what is satellite assembly?
A satellite assembly is a .NET Framework assembly containing resources specific to a given language. Using satellite assemblies, you can place resources for different languages in different assemblies, and the correct assembly is loaded into memory only if the user selects to view the application in that language.
Satellite assembly is used to develop multi lingual applications in .net
22)what are multilingual applications?
The applications that are build in supportive of more than one human readle language are known as multilingual applications.
23)what is the difference betwen
a=b assignin b to a
a==b comparing a with b
a.Equals(b) comparing 2 objects
24)what is the use of codesnippets?
code snippet is one of the best and easiest way for any developer to increase code productivity simply shortcuts.
25)what is the difference between Array and collection?
Array
Array is of fixed size
Array is the collection of values of the same data type
Array mainly used to save variables of same data type temporarily until the progarmming in running
>the variables in an array is called array elements
>Array is a reference type data type
ArrayList
-ArrayList is allowed to grow as needed
-Array list are collection of objects of same type or different type.
-Its a Collection of Objects with Sorting Feature.
-Array list is used to store and retrieve the variables of different data type.
-Array list is a class .
26) what is a class?
class is a keyword which is used to achieve Encapsulation
class is a userdefined reference type datatype which consits of variables and methods
27)what is the difference betwee class and structure?
class:-
class is reference type where structure is value type
The memory for the members of the class
will be allocated on heap memory where the memory for the members of structure will be on stack
class supports inheritance but structure doesnot support inheritance
class contains constructors where as structors cannot contain constructors
28)what is Encapsulation?
29)what is DataAbstraction?
30)what is the constructor?
31)what is the difference between constructor and method?
32)what is the difference between private constructor constructor?
private constructor is used to initialize the values for instance variables
static constructor is used to initialize the values for static variables.
we cannot create an object for the class having private constructor outside the class.
we can create an object for the class have static constructor outside the class.
33)when the static constructor will be called?
static constructor will be befor ecreating an object the call to the static constructor will be done by CLR
34)can we declare static Accessspecifiers for static constructor ?
No beacuse the call to the static constructor is by CLR
35) Can we declare parameterised static constructor?
No
36)can we override properties?
yes with get accessor
37) What is the use of properties?
properties are used to transfer the data
38)if we declare Main() and static constructor in same class which one will execute first?
static constructor
39)How to call defualt constructor of one class with parametersised constructor of same class?
this()
40)How to call defualt constructor of base class with parametersised constructor of derived class?
base()
41)does C# support multiple inheritance?
No through interfaces we can achieve
42)what is overloading?
43)what is overriding?
44)How to restrict a class from inheritance?
sealed class
45)how to stop overrriding?
sealed method
46)what is a delegate?
delegate is a type safe function pointer which is used to develop event driven programming.
47)what is the difference between Event and method?
method will have returntype and event will not have return type
48)what are generics?
Generics are general datatype which are used to avoid unnecessary boxing and unbocing and to avoid overloading
49)Does generics support arthimetic perators?
no
50)Can we use Properties in interface?
Yes we can use automatic properties but we have to implement in derived class.

Comments

Popular posts from this blog

What is cookie? Advantages and disadvantages of cookies?

What is cookie? A cookie is a small piece of text file stored on user's computer in the form of name-value pair. Cookies are used by websites to keep track of visitors e.g. to keep user information like username etc. If any web application using cookies, Server send cookies and client browser will store it. The browser then returns the cookie to the server at the next time the page is requested. The most common example of using a cookie is to store User information, User preferences, Password Remember Option etc.It is also one of the common and mostly asked interview questions. Some facts about Cookie Here are a few facts to know about cookies: · Cookies are domain specific i.e. a domain cannot read or write to a cookie created by another domain. This is done by the browser for security purpose. · Cookies are browser specific. Each browser stores the cookies in a different location. The cookies are browser specific and so a cookie created in one browser(e.g in Google Chrome

Code First Getting Started

In this tutorial let us create a simple application to demonstrate the use of entity framework using code first. We are using Visual Studio 2015 and entity framework 6.1.3. You can download Visual Studio community Edition . You should have the basic knowledge of .Net framework, C# and MS SQL Server. In this tutorial, we will create a simple application with a user class.  Our user class will have basic information like name and email address of the user. Create the Project Open Visual Studio. File ->New -> Project Select C# -> Select Console Application Name the application as “EFGettingStarted” Click on OK Install Entity Framework The next step is to install the Entity framework. This can be installed via nuget package console. Click on Tools->Nuget Package manager -> Package Manager Console and type the following command C# 1 2 3   install - package entityframework   This will install the late

First, FirstOrDefault, Single, SingleOrDefault In C#

For people who are new to LINQ, it is difficult to understand the difference between First, FirstOrDefault, Single, SingleOrDefault. In this blog, I will explain what to use and when.     I will take a simple example to make you understand practically how these methods work.   Consider a class Employee with properties as Id, Name, and Department. class  Employee {    public   int  Id {  get ;  set ; }    public   string  Name {  get ;  set ; }    public   string  Department{  get ;  set ; } } I have a list of Employees: List<Employee> employeeList =  new  List<Employee>(){    new  Employee() { Id = 1, Name =  "Sunny" , Department =  "Technical"  },    new  Employee() { Id=2, Name= "Pinki" , Department = "HR" },    new  Employee() { Id=3, Name= "Tensy" , Department = "Finance" },    new  Employee() { Id=4, Name= "Bobby" , Department = "Technical" },    new