.Net Framework Interview Questions 5

By | May 12, 2014

How many .NET languages can a single .NET DLL contain?
One

What type of code (server or client) is found in a Code-Behind class? Server

Whats an assembly? Assemblies are the building blocks of .NET Framework applications; they form the fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the common language runtime with the information it needs to be aware of type implementations. To the runtime, a type does not exist outside the context of an assembly.

How many classes can a single .NET DLL contain? Unlimited.

What is the difference between string and String ? No difference

What is manifest? It is the metadata that describes the assemblies.

What is metadata? Metadata is machine-readable information about a resource, or “”data about data.”” Such information might include details on content, format, size, or other characteristics of a data source. In .NET, metadata includes type definitions, version information, external assembly references, and other standardized information.

What are the types of assemblies? There are four types of assemblies in .NET: Static assemblies These are the .NET PE files that you create at compile time. Dynamic assemblies These are PE-formatted, in-memory assemblies that you dynamically create at runtime using the classes in the System.Reflection.Emit namespace. Private assemblies These are static assemblies used by a specific application. Public or shared assemblies These are static assemblies that must have a unique shared name and can be used by any application. An application uses a private assembly by referring to the assembly using a static path or through an XML-based application configuration file. While the CLR doesn’t enforce versioning policies-checking whether the correct version is used-for private assemblies, it ensures that an application uses the correct shared assemblies with which the application was built. Thus, an application uses a specific shared assembly by referring to the specific shared assembly, and the CLR ensures that the correct version is loaded at runtime. In .NET, an assembly is the smallest unit to which you can associate a version number;

What are delegates?where are they used ? A delegate defines a reference type that can be used to encapsulate a method with a specific signature. A delegate instance encapsulates a static or an instance method. Delegates are roughly similar to function pointers in C++; however, delegates are type-safe and secure.

When do you use virutal keyword?. When we need to override a method of the base class in the sub class, then we give the virtual keyword in the base class method. This makes the method in the base class to be overridable. Methods, properties, and indexers can be virtual, which means that their implementation can be overridden in derived classes.

What are class access modifiers ? Access modifiers are keywords used to specify the declared accessibility of a member or a type. This section introduces the four access modifiers: · Public  – Access is not restricted. · Protected  – Access is limited to the containing class or types derived from the containing class. · Internal – Access is limited to the current assembly. · Protected inertnal – Access is limited to the current assembly or types derived · from the containing class. · Private – Access is limited to the containing type.

What Is Boxing And Unboxing? Boxing :- Boxing is an implicit conversion of a value type to the type object type Eg:- Consider the following declaration of a value-type variable: int i = 123; object o = (object) i; Boxing Conversion UnBoxing :- Unboxing is an explicit conversion from the type object to a value type Eg: int i = 123;          // A value type object box = i;       // Boxing int j = (int)box;     // Unboxing

What is Value type and refernce type in .Net?. Value Type : A variable of a value type always contains a value of that type. The assignment to a variable of a value type creates a copy of the assigned value, while the assignment to a variable of a reference type creates a copy of the reference but not of the referenced object. The value types consist of two main categories: * Stuct Type * Enumeration Type Reference Type :Variables of reference types, referred to as objects, store references to the actual data. This section introduces the following keywords used to declare reference types: * Class * Interface * Delegate This section also introduces the following built-in reference types: * object * string

What is the difference between structures and enumeration?. Unlike classes, structs are value types and do not require heap allocation. A variable of a struct type directly contains the data of the struct, whereas a variable of a class type contains a reference to the data. They are derived from System.ValueType class. Enum->An enum type is a distinct type that declares a set of named constants.They  are strongly typed constants. They are unique types that allow to declare symbolic names to integral values. Enums are value types, which means they contain their own value, can’t inherit or be inherited from and assignment copies the value of one enum to another. public enum Grade {    A,    B,    C }

What is namespaces?. Namespace is a logical naming scheme for group related types.Some class types that logically belong together they can be put into a common namespace. They prevent namespace collisions and they provide scoping. They are imported as “using” in C# or “Imports” in Visual Basic. It seems as if these directives specify a particular assembly, but they don’t. A namespace can span multiple assemblies, and an assembly can define multiple namespaces. When the compiler needs the definition for a class type, it tracks  through each of the different imported namespaces to the type name and searches each referenced assembly until it is found. Namespaces can be nested. This is very similar to packages in Java as far as scoping is concerned.

How do you create shared assemblies?. Just look through the definition of Assemblies..    *  An Assembly is a  logical unit of code    * Assembly physically exist as DLLs or EXEs    * One assembly can contain one or more files    * The constituent files can include any file types like image files, text files etc. along with DLLs or EXEs    * When you compile your source code by default the exe/dll generated is actually an assembly    * Unless your code is bundled as assembly it can not be used in any other application    * When you talk about version of a component you are actually talking about version of the assembly to which the component belongs.    * Every assembly file contains information about itself. This information is called as Assembly Manifest. Following steps are involved in creating shared assemblies :    * Create your DLL/EXE source code    * Generate unique assembly name using SN utility    * Sign your DLL/EXE with the private key by modifying AssemblyInfo file    * Compile your DLL/EXE    * Place the resultant DLL/EXE in global assembly cache using AL utility   

What is global assembly cache? Each computer where the common language runtime is installed has a machine-wide code cache called the global assembly cache. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.  There are several ways to deploy an assembly into the global assembly cache: · Use an installer designed to work with the global assembly cache. This is the preferred option for installing assemblies into the global assembly cache. · Use a developer tool called the Global Assembly Cache tool (Gacutil.exe), provided by the .NET Framework SDK. · Use Windows Explorer to drag assemblies into the cache.  

What is MSIL?. When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Before code can be run, MSIL must be converted to CPU-specific code, usually by a just-in-time (JIT) compiler. Because the common language runtime supplies one or more JIT compilers for each computer architecture it supports, the same set of MSIL can be JIT-compiled and run on any supported architecture. When a compiler produces MSIL, it also produces metadata. Metadata describes the types in your code, including the definition of each type, the signatures of each type’s members, the members that your code references, and other data that the runtime uses at execution time. The MSIL and metadata are contained in a portable executable (PE) file that is based on and extends the published Microsoft PE and common object file format (COFF) used historically for executable content. This file format, which accommodates MSIL or native code as well as metadata, enables the operating system to recognize common language runtime images. The presence of metadata in the file along with the MSIL enables your code to describe itself, which means that there is no need for type libraries or Interface Definition Language (IDL). The runtime locates and extracts the metadata from the file as needed during execution.

What is Jit compilers?.how many are available in clr? Just-In-Time compiler- it converts the language that you write in .Net into machine language that a computer can understand. there are tqo types of JITs one  is memory optimized & other  is performace optimized.

What is tracing?Where it used.Explain few methods available Tracing refers to collecting information about the application while it is running. You use tracing  information to troubleshoot an application. Tracing allows us to observe and correct programming errors. Tracing enables you to record information in various log files about the errors that might occur at run time. You can analyze these log files to find the cause of the errors. In .NET we have objects called Trace Listeners. A listener is an object that receives the trace output and outputs it somewhere; that somewhere could be a window in your development environment, a file on your hard drive, a Windows Event log, a SQL Server or Oracle database, or any other customized data store. The System.Diagnostics namespace provides the interfaces, classes, enumerations and structures that are used for tracing The System.Diagnostics namespace provides two classes named Trace and Debug that are used for writing errors and application execution information in logs. All Trace Listeners have the following functions. Functionality of these functions is same except that the target media for the tracing output is determined by the Trace Listener. Method Name Result Fail   Outputs the specified text with the Call Stack. Write   Outputs the specified text. WriteLine    Outputs the specified text and a carriage return. Flush   Flushes the output buffer to the target media. Close   Closes the output stream in order to not receive the tracing/debugging output.

Leave a Reply