C Sharp Interview Questions & Answers part 1

0
321

Q: – What is c#(c sharp programming language)?

C# (pronounced see sharp) is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines. It was developed by Microsoft within its .NET initiative. C# is one of the programming languages designed for the Common Language Infrastructure.

Q: – Explain the elements of the .NET Framework.

  • CLR (Common Language Runtime): It is a common managed environment where all the .net programs run. Supports multiple languages and has the garbage collector.
  • .Net Framework Class Libraries: For each source code compiler (VB.NET, C#.NET, etc.), there is a minimum set of coding standards that must be met. The minimum set of coding standards that must be met to compile .NET code into MSIL code is known as CLS – Common Language Specification. The role of the Common Language Specification is to ensure that all generated code (MSIL) that meets the minimum set of coding standards can operate successfully within the .NET framework. THE CTS (Common Type System) handles conversion of programming-language data types into .NET compatible (MSIL) data types. The implicit benefit of the CTS is the reduction of development time when attempting to coordinate data types between two sets of different programming-language code.
  • Data and XML: Support for disconnected programming model and XML.
  • XML webservices: creating webservices for distributed architecture.
  • Webforms: Provides support and functionality for Web based UI.
  • Windows forms: Provides support and functionality for Windows based UI.

Q: – What is assembly manifest? What is the information it provides ?

Assembly Manifest is a file that contains data that describes how the elements present inside an assembly are connected to each other. The assembly manifest contains assembly metadata to define the scope of the assembly and resolve references to resources and classes.

Information provided by Assembly Manifest:

  • Assembly Name
  • Version Number
  • Culture
  • Strong name
  • List of files inside the assembly
  • Reference information

Q: – Explain how a .NET application is compiled and executed ?

Any code written in any .NET complaint languages when compiled, converts into MSIL (Microsoft Intermediate Language) code in form of an assembly through CLS, CTS. IL is the language that CLR can understand. On execution, this IL is converted into binary code by CLR’s just in time compiler (JIT) and these assemblies or DLL are loaded into the memory.

Q: – Describe the .NET base class library ?

.NET’s Base class library exists in order to encapsulate huge number of common functions and makes them easily accessible to the developer. .NET base class library provides the functionality like ADO.NET, XML, Threading, IO, Security, Diagnostics, Resources, Globalization, collections etc. It serves as the main point of interaction between developer and runtime.

Q: – Explain the difference between value types and reference types in C# ?

Value Type:
Stores the data.
The value of value types is stored on the managed stack.
One variable can have just one value.
They are lighter objects.
Reference Type:

  • Stores the reference to the data.
  • A reference type is allocated on the heap.
  • several variables can reference the same data
  • They are heavier objects.

Q: – Explain the importance of Imports and Using Statements.

Import statement: creates a property on the global object with the name supplied as namespace and initializes it to contain the object that corresponds to the namespace being imported. Any properties created using the import statement cannot be assigned to, deleted, or enumerated. All import statements are executed when a script starts.

Using statements: mainly defines the namespaces whose objects will be used in the form. This clearly solves 2 purposes: Defines all the namespaces that will be used in a form. Secondly, reduces the hassle for the programmer to type the name of namespace again and again while using classes/objects that belong to the namespace.

Q: – Explain the difference between a class and a structure

Class :

  • It is reference type.
  • Null value can be assigned to a variable in a class
  • It can have destructor.
  • All variables in classes are by default private.
  • Good to be used from architecture view as it provides high flexibility.

Structure:

  • It is value type.
  • Null value assignment is not feasible here.
  • Cannot have destructor.
  • All variables in structures are public.
  • Good to be used for simple data structures.

Q: – Explain how garbage collection manages the reclaimation of unused memory.

The garbage collector assumes that all objects in the managed heap are garbage. It starts walking the roots and builds a graph of all objects reachable from the roots recursively. It stops when it attempts to add an object to the graph that it previously added. The graph contains the set of all objects that are reachable from the application's roots. Any object/s that is not in the graph is not accessible by the application, and is considered garbage. Collection only occurs when the heap is full. In such a case, each and every garbage object calls the Finalize method and reclaims the unused memory.

Submitted By:-Goyal Ankur            Email-ID: – goyal.ankur30@yahoo.in

 

SHARE

LEAVE A REPLY