C# interview questions and answers part 1

1) what is CLR?

   CLR is the virtual machine component of Microsoft's .NET framework Cwhich is used for memory management and debubbing

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 valuetype
   int? a = null;
   Nullable datatypes are introduced from .net 2.0 and above bersions.

4) what is the default datatype to store integer value?


5) what is the default datatype to store decimal value?


6) what is the Difference between ToString() and Convert.ToString()?

   ToString() doesnot handle null values
   Convert.ToString()will handle null values.
   object o = null;
   string s;
   // s = o.ToString();
   string str = Convert.ToString(o);

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 and 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;
   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.
     byte b=255;
   o/p: A runtime error will occur saying that
   Arithmetic operation resulted in an overflow.

10) wap to get the range of byte?


11) what is the difference between typeOf() and sizeOf()?

   typeOf() will get the base datatype name
   sizeOf() will get the size of the datatype

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 i=10;
     long 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;

14) what is the difference between string and stringbuilder?

   Both string and StringBuilder are classes.
   string is immutable and stringbuilder is mutable
   immutable meand 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 for string
      class Program
         { static void Main()
            { string x = "";
              for (int i = 0; i < 2; i++)
                 { x = "sathya" + 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.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?

    Visual studio Tools--->

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

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 between?

    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 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 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 .
About Author: author 4 + years of Information Technology experience in understanding and analyzing the software and hardware engineering requirements, onsite and offshore management of product development. Expert work on design and development for windows,web,mobile Expert knowledge of C#,ADO.NET, ASP.Net MVC, ENTITY FRAMEWORK, LINQ,COLLECTIONS, JAVASCRIPT,AngularJs 1.0,Angular2, Jquery,Jquery-Ajax, SQL SERVER, XAML,Windows phone 8.1 Good knowledge of WCF-Restful services,WCF, WEB API-Services ,Web- Services,MIcrosoft-Azure,JUICE UI,HTML,CSS,AJAX Read More...

Join him on Google+ | Facebook | Linkedin

1 comment