Advanced C# Interview Questions & Answers

5 avg. rating (100% score) - 4 votes

Advanced C# Interview Questions & Answers

Have you prepared to attend the job interview? Are you confused in job preparation? Then no problem we have the right solution you in in our site page. If you are familiar with the Advanced topics of C# then there are many leading companies that offer job roles like Software Development - C#, Full Stack Developer - C#, C# Developer/senior Developer, Web Developer - C#, and many other leading roles too. If you are preparing for Advanced C# job interview and don’t know how to crack interview and what level or difficulty of questions to be asked in job interviews then go through Wisdomjobs Advanced C# interview questions and answers page to crack your job interview. Underneath are the commonly asked Advanced C# job interview questions and answers which can make you feel relaxed to face the interviews:

Advanced C# Interview Questions

Advanced C# Interview Questions
    1. Question 1. What Is Attribute In C#?

      Answer :

      An attributes is a declarative tag that is used to convey information about the behaviors of various elements (classes, methods, assemblies, structures, enumerators, etc). it is access at compile time or run-time. Attributes are declare with a square brackets [] which is places above the elements.

      [Obsolete(“Don’t use Old method, please use New method”, true)]

      For example consider the bellow class. If we call the old method it will through error message.

      public class myClass

      {

          [Obsolete("Don't use Old method, please use New method", true)]

          public string Old() { return "Old"; }

          public string New() { return "New"; }

      }

      myClass omyClass = new myClass();

      omyClass.Old();

    2. Question 2. Why Attributes Are Used?

      Answer :

      In a program the attributes are used for adding metadata, like compiler instruction or other information (comments, description, etc).

    3. Question 3. What Are The Types Of Attributes?

      Answer :

      The Microsoft .Net Framework provides two types of attributes: the pre-defined attributes and custom built attributes.

      Pre-define attributes are three types:

      • AttributeUsage
      • Conditional
      • Obsolete

      This marks a program that some entity should not be used.

    4. Question 4. What Is Custom Attributes?

      Answer :

      The Microsoft .Net Framework allows creating custom attributes that can be used to store declarative information and can be retrieved at run-time.

    5. Question 5. What Is Reflection?

      Answer :

      Reflection is a process by which a computer program can monitor and modify its own structure and behavior. It is a way to explore the structure of assemblies at run time (classes, resources, methods). Reflection is the capability to find out the information about objects, metadata, and application details (assemblies) at run-time. We need to include System.Reflection namespace to perform reflections in C#. For example consider the following C# codes, which will returns some meta information’s.

      public class MyClass

      {

          public virtual int Add(int numb1, int numb2)

          {                

              return numb1 + numb2;

          }

          public virtual int Subtract(int numb1, int numb2)

          {

              return numb1 - numb2;

          }

      }

      static void Main(string[] args)

      {

          MyClass oMyClass = new MyClass();

          //Type information.

          Type oMyType = oMyClass.GetType();

          //Method information.

      MethodInfo oMyMethodInfo = oMyType.GetMethod("Subtract");

      Console.WriteLine("nType information:" + oMyType.FullName);

       Console.WriteLine("nMethod info:" + oMyMethodInfo.Name);            

      Console.Read();

      }

    6. Question 6. Why We Need Reflection In C#?

      Answer :

      Reflections needed when we want to determine / inspect contents of an assembly. For example: at Visual Studio editor intelligence, when we type “.” (dot) before any object, it gives us all the members of the object. This is possible for Reflection.

      Beside this we need reflection for the following purposes:

      • To view attribute information at run time
      • To view the structure of assemblies at run time (classes, resources, methods)
      • It allows dynamic/late binding to methods and properties
      • In serialization, it is used to serialize and de-serialize objects
      • In web service, it is used to create and consume SOAP messages and also to generate WSDL
      • Debugging tools can use reflection to examine the state of an object.

    7. Question 7. What Is Dynamic Keyword?

      Answer :

      The dynamic is a keyword which was introduced in .NET 4.0. Computer programming languages are two types: strongly typed and dynamically typed. In strongly types all types checks are happened at compile time, in dynamic types all types of checks are happened at run time.

      For example consider the following code

      dynamic x = "c#";

      x++;

      It will not provide error at compile time but will provide error at run time.

    8. Question 8. When To Use Dynamic?

      Answer :

      The biggest practical use of the dynamic keyword is when we operate on MS Office.

    9. Question 9. What Is The Difference Between Reflection And Dynamic?

      Answer :

      Both Reflection and dynamic are used to operate on an object during run time. But they have some differences:

      • Dynamic uses reflection internally
      • Reflection can invoke both public and private members of an object. But dynamic can only invoke public members of an object

    10. Question 10. What Is Serialization?

      Answer :

      When we want to transport an object through network then we need to convert the object into a stream of bytes. Serialization is a process to convert a complex objects into stream of bytes for storage (database, file, cache, etc) or transfer. Its main purpose is to save the state of an object.

      De-serialization is the reverse process of creating an object from a stream of bytes to their original form.

    11. Question 11. What Are The Types Of Serialization?

      Answer :

      The types of Serializations are given bellow:

      1  Binary Serialization
                  In this process all the public, private, read only members are serialized and convert into stream of bytes. This is used when we want a complete conversion of our objects.
      2  SOAP Serialization
                 In this process only public members are converted into SOAP format. This is used in web services.
      3  XML Serialization
                  In this process only public members are converted into XML. This is a custom serialization. Required namespaces: System.Xml, System.Xml.Serialization.

    12. Question 12. Why Serialization And Deserialization?

      Answer :

      For example consider, we have a very complex object and we need XML format to show it on HTML page. Then we can create a XML file in the disk, writes all the necessary data on the XML file, and use it for the HTML page. But this is not good approach for large number of users. Extra space is required; anyone can see the XML file which creates security issue. We can overcome it by using XML serialization.

    13. Question 13. When To Use Serialization?

      Answer :

      Serialization is used in the following purposes:

      • To pass an object from on application to another
      • In SOAP based web services
      • To transfer data through cross platforms, cross devices

    14. Question 14. Give Examples Where Serialization Is Used?

      Answer :

      Serialization is used to save session state in ASP.NET applications, to copy objects to the clipboard in Windows Forms. It is also used to pass objects from one application domain to another. Web services uses serialization.

    15. Question 15. What Is Generics?

      Answer :

      Generics are the most powerful features introduced in C# 2.0. It is a type-safe data structure that allows us to write codes that works for any data types.

    16. Question 16. What Is A Generic Class?

      Answer :

      A generic class is a special kind of class that can handle any types of data. We specify the data types during the object creations of that class. It is declared with the bracket <>. For example consider the following Comparer class, which has a method that compare two value and returns as Boolean output.

      public class Comparer

      {

          public bool Compare(Unknown t1, Unknown t2)

        {  

               if (t1.Equals(t2))

            {

                  return true;

              }

              else

              {

                  return false;

              }

          }

      }

      Comparer oComparerInt = new Comparer();

      Console.WriteLine(oComparerInt.Compare(10, 10));

      Comparer oComparerStr = new Comparer();

      Console.WriteLine(oComparerStr.Compare("jdhsjhds", "10"));

    17. Question 17. Why We Should Use Generics?

      Answer :

      Generic provides lot of advantages during programming. We should use generics for the following reasons:

      • It allows creating class, methods which are type-safe
      • It is faster. Because it reduce boxing/un-boxing
      • It increase the code performance
      • It helps to maximize code reuse, and type safety

    18. Question 18. What Is Collections In C#?

      Answer :

      Sometimes we need to work with related objects for data storage and retrieval. There are two ways to work with related objects. One is array and another one is collections. Arrays are most useful for creating and working with a fixed number of strongly-typed objects. Collections are enhancement of array which provides a more flexible way to work with groups of objects.

      The Microsoft .NET framework provides specialized classes for data storage and retrieval. Collections are one of them. Collection is a data structure that holds data in different ways. Collections are two types. One is standard collections, which is found under System.Collections namespace and another one is generic collections, which is found under System.Collections.Generic namespace.The generic collections are more flexible and preferable to work with data.

      Some commonly used collections under System.Collections namespace are given bellow:

      • ArrayList
      • SortedList
      • Hashtable
      • Stack
      • Queue
      • BitArray

    19. Question 19. What Is Unsafe Code?

      Answer :

      In order to maintain security and type safety, C# does not support pointer generally. But by using unsafe keyword we can define an unsafe context in which pointer can be used. The unsafe code or unmanaged code is a code block that uses a pointer variable. In the CLR, unsafe code is referred to as unverifiable code. In C#, the unsafe code is not necessarily dangerous. The CLR does not verify its safety. The CLR will only execute the unsafe code if it is within a fully trusted assembly. If we use unsafe code, it is our own responsibility to ensure that the code does not introduce security risks or pointer errors.

    20. Question 20. What Are The Properties Of Unsafe Code?

      Answer :

      Some properties of unsafe codes are given bellow:

      • We can define Methods, types, and code blocks as unsafe
      • In some cases, unsafe code may increase the application’s performance by removing array bounds checks
      • Unsafe code is required in order to call native functions that require pointers
      • Using unsafe code brings security and stability risks
      • In order to compile unsafe code, the application must be compiled with /unsafe

    21. Question 21. Can Unsafe Code Be Executed In Untrusted Environment?

      Answer :

      Unsafe code cannot be executed in an un-trusted environment. For example, we cannot run unsafe code directly from the Internet.

    22. Question 22. How To Compile Unsafe Code?

      Answer :

      For compiling unsafe code, we have to specify the /unsafe command-line switch with command-line compiler.

      For example: to compile a program named “myClass.cs” containing unsafe code the command line command is:

      csc /unsafe myClass.cs

      In Visual Studio IDE at first we need to enable use of unsafe code in the project properties.

      The steps are given bellow:

      1. Open project properties
      2. Click on the Build tab
      3. Select the option “Allow unsafe code”

    23. Question 23. What Is Pointer?

      Answer :

      Pointer is a variable that stores the memory address of another variable. Pointers in C# have the same capabilities as in C or C++.

      Some examples are given bellow:

      1. int    *i    // pointer of an integer
      2. float  *f    // pointer to a float
      3. double *d    // pointer to a double
      4. char   *ch   // pointer to a character

    24. Question 24. Should I Use Unsafe Code In C#?

      Answer :

      In C#, pointer is really used and Microsoft disengaged to use it. But there are some situations that require pointer. We can use pointer if required at our own risk. Some sonorous are given bellow:

      • To deal with existing structures on disk
      • Some advanced COM or Platform Invoke scenarios that involve pointer
      • To performance critical codes

    25. Question 25. How Can We Sort The Elements Of The Array In Descending Order ?

      Answer :

      For This,First we call the Sort () method and then call Reverse() Methods.

    26. Question 26. Can We Store Multiple Data Types In System.array ?

      Answer :

      No.

    27. Question 27. What Is The Difference Between The System.array.copyto() And System.array.clone() ?

      Answer :

      System.Array.CopyTo()-->It require a destination array to be existed before and it must be capable to hold all the elements in the source array from the index that is specified to copy from the source array.

      System.Array.Clone()-->It does not require the destination array to be existed as it creates a new one from scratch.

      Note-These both are used as a shallow copy.

    28. Question 28. What Is Difference Between String And Stringbuilder ?

      Answer :

      StringBuilder is more efficient than string.

      String :- It is Immutable and resides within System Namespace.

      StringBuilder:-It is mutable and resides System.Text Namespace.

    29. Question 29. What Is Class Sortedlist Underneath?

      Answer :

      It is a Hash Table.

    30. Question 30. What Is The .net Data Type That Allow The Retrieval Of Data By A Unique Key ?

      Answer :

      Hash Table

    31. Question 31. Is Finally Block Get Executed If The Exception Is Not Occured ?

      Answer :

      Yes.

    32. Question 32. Can Multiple Catch () Block Get Executed If The Exception Is Not Occured ?

      Answer :

      No,Once the proper catch code fires off ,the control is transferred to the finally block(if any),and the whatever follows the finally block.

    33. Question 33. What Is Multicast Delegate ?

      Answer :

      The Multicast delegate is a delegate that points to and eventually fires off several methods.

    34. Question 34. What Are The Ways To Deploy An Assembly ?

      Answer :

      • An MSI Installer
      • A CAB archive
      • XCopy command

    35. Question 35. What Is The Dll Hell Problem Solved In .net ?

      Answer :

      In .NET, Assembly versioning allows the application to specify not only the library it needs to run ,but also the version of the assembly.

    36. Question 36. What Is A Satellite Assembly ?

      Answer :

      When we write the code, a  multicultural or multilingual application in .NET and want to distribute the core application separately from the localized modules,the localized assemblies that modify the core application ,that is known  as Satellite assembly.

    37. Question 37. How Do We Inherit From A Class In C# ?

      Answer :

      In c#, we use a colon (:) and then the name of the base class.

    38. Question 38. Does C# Support Multiple Inheritance ?

      Answer :

      No, we use interface for this purpose.

    39. Question 39. Are Private Class -label Variables Inherited ?

      Answer :

      Yes, but it is not accessible.we generally know that they are inherited but not accessible.

    40. Question 40. What Is The Implicit Name Of The Parameter That Gets Passed Into Class "set" Method ?

      Answer :

      Value and it's datatype(it depends whatever variable we are changing).

    41. Question 41. What Is The Top .net Class ?

      Answer :

      System.Object

    42. Question 42. How Does Method Overloading Different From Overriding ?

      Answer :

      A method overloading simply involves having a method with the same name within the class. whereas in method overriding we can change method behaviour for a derived class.

    43. Question 43. Can We Override Private Virtual Method ?

      Answer :

      No.

    44. Question 44. Can We Declare The Override Method Static While The Original Method Is Non Static ?

      Answer :

      No.

    45. Question 45. Can We Prevent My Class From Being Inherited And Becoming A Base Class From The Other Classes ?

      Answer :

      Yes.

    46. Question 46. What Is An Interface Class ?

      Answer :

      This is an abstract class with public abstract methods , all of which must be implemented in the inherited classes.

    47. Question 47. Can We Inherit Multiple Interfaces ?

      Answer :

      Yes.

    48. Question 48. Can We Allow Class To Be Inherited ,but Prevent The Method From Being Overridden ?

      Answer :

      Yes, first create class as public and make it's method sealed.

    49. Question 49. What Is Signature Used For Overloaded A Method ?

      Answer :

      • Use different data types
      • Use different number of parameters
      • Use different order of parameters

    50. Question 50. What Is The Difference Between An Interface And Abstract Class ?

      Answer :

      In an interface, all methods must be abstract but in abstract class some methods can be concrete.In interface No accessibility modifiers are alloweded but in abstract class a accessibility modifier are alloweded.

C#. Net Tutorial

Advanced C# Interview Questions

Advanced C# Practice Tests

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

C#. NET Tutorial