0% found this document useful (0 votes)
50 views

Dot Net Questions: Explain The Concepts of CTS and CLS (Common Language Specification)

Uploaded by

Vikas Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Dot Net Questions: Explain The Concepts of CTS and CLS (Common Language Specification)

Uploaded by

Vikas Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DOT NET QUESTIONS

Describe how a .Net application is compiled and executed.     

From the source code, the compiler generates Microsoft Intermediate Language (MSIL) which is further used for
the creation of an EXE or DLL. The CLR processes these at runtime. Thus, compiling is the process of
generating this MSIL.

The way you do it in .Net is as follows:

Right-click and select Build / Ctrl-Shift-B / Build menu, Build command


F5 - compile and run the application. 
Ctrl+F5 - compile and run the application without debugging.

Compilation can be done with Debug or Release configuration. The difference between these two is that in the
debug configuration, only an assembly is generated without optimization. However, in release complete
optimization is performed without debug symbols

Explain the components of common language runtime.

a. Class Loader: is an abstract class. Its purpose is to tell JVM in what manner a class is to be loaded at runtime.

b. MSIL: Microsoft Intermediate Language is considered to be the lowest form of human readable language. It is
CPU independent and includes instructions of how to load, store, initialize objects. JIT converts this MSIL into
native code which is dependent on the CPU.

c. Code Manager: Is responsible for managing code at runtime.

d. Garbage Collector: The .NET garbage collector enables high-speed allocation and release of memory for the
objects in managed code. Its main aim is proper memory management.

e. Security Engine: It ensures all the security restrictions.

f. Type Checker: It enforces the constraints of types. It enforces strictness in type checking.

g. Thread Support: It allows multithreading

h. Debug engine: It allows proper debugging of an application.

i. Base class library: It provides all the types that an application need at runtime.

j. Exception manager: Handles all the exception for an application during runtime.

k. COM Marshaller: It provides an option for interoperability for an application

Explain the concepts of CTS and CLS(Common Language Specification).

CTS

When different languages are integrated and want to communicate, it is certain that the languages have their
own data types and different declaration styles. CTS define how these different variables are declared and used
in run time. E.g. VB offers an Integer data type while C++ offers long data type. Using CTS, these data types are
converted to System32 which itself a data type of CLS.

CLS
Any language(s) that intend to use the Common Language Infrastructure needs to communicate with other CLS-
Compliant language. This communication is based on set of rules laid by CLS. These rules define a subset of
CTS.

Explain the use of virtual, sealed, override, and abstract.

The virtual keyword enables a class to be overridden. If it has to be prevented from being overridden, then the
sealed keyword needs to be used. If the keyword virtual is not used, members of the class can even then be
overridden. However, its usage is advised for making the code meaningful.

The override keyword is used to override the virtual method in the base class. Abstract keyword is used to modify
a class, method or property declaration. You cannot instantiate an abstract class or make calls to an abstract
method directly.

An abstract virtual method means that the definition of the method needs to be given in the derived class.

What is a CLR (Common Language Runtime)?

Often there is a need for different languages to communicate with each other at run time. For e.g. A class may be
written in one language and its derived class may be written in a different language. Common Language Runtime
is a run time environment for .NET. These different languages are integrated and can communicate easily
because language compilers and tools that target the runtime use a common type system defined by the runtime.

Features or Functionalities offered by CLR:-

 Garbage collection for managing life of objects.

 Enables Cross language inheritance as explained in example above.

 Syntax and keywords similar to C and C++

What is Operator Overloading in .NET?

Operator overloading is the most evident example of Polymorphism. In operator overloading, an operator is
‘overloaded’ or made to perform additional functions in addition to what it actually does. For e.g. we can overload
the “+” operator to add two complex numbers or two imaginary numbers.

X= a + b //+ is overloaded to add two integers, float etc


Few operators like :: cannot be overloaded.

Difference between Association, Aggregation and Inheritance relationships.

An Association is a relationship between similar objects or objects with common structures.

Example: 
An employee object is associated with manager object.
Aggregation is “a part of” relationship.
Example:
A student object is a part of College object.
Inheritance is a “is a “relationship where one or more classes are derived from a base class. The derived class
has the base class plus its own characteristics.
Example:
French_Student class can be a derived class of student class.

Describe the programming model of a windows service.


Windows services are based on the class that is inherited from System.ServiceProcess.ServiceBase class.
Methods from this class are overridden to provide the functionality as per the user’s requirement. The important
classes involved in service creation are:

a. ServiceBase 
a. OnStart
b. OnPause
c. OnStop
d. OnContinue
e. OnShutdown
f. OnCustomCommand
g. OnPowerEvent
b. ServiceProcessInstaller
c. ServiceInstaller
d. ServiceController

Explain the states of a window service application

a. Running: Normal operation occurs during this stage.

b. Paused: The service cannot perform anything beyond till the paused state is changed.

c. Stopped: The application based on this service will not work until the service is started once again.

d. Pending: Running is the stage which comes after Pending.

Explain the types of window services.

Win32OwnProcess
Win32ShareProcess

a. Win32OwnProcess: It is a Win32 process that can be started by the Service Controller. This type of Win32
service runs in a process by itself.

b. Win32ShareProcess: It is a Win32 service that allows sharing of processes with other Win32 services.

Discuss about imperative and declarative security.

Declarative security: Security requests are made in form of attributes.

e.g.:

<MyPermission(SecurityAction.Demand, Unrestricted = True)> Public Class MyCustomClass


     Public Sub New()
             'The constructor is protected by the security call.
     End Sub
     Public Sub Method1()
            'This method is protected by the security call.
     End Sub
     Public Sub Method2()
            'This method is protected by the security call.
     End Sub
End Class

Imperative security:security requests are made in the form of lines of code within a method body.Basically an
instance of permission object is created that needs to be invoked.
e.g.:

Public Class MyCustomClass


      Public Sub New()
      End Sub
      Public Sub Method1()
          'MyPermission is demanded using imperative syntax.
           Dim permission As New MyPermission()
           permission.Demand()
           'This method is protected by the security call.
      End Sub
      Public Sub Method2()
               'YourMethod 'This method is not protected by the security call.
      End Sub
End Class

What do you understand by side-by-site execution of assembly?

Side by side execution refers to running/execution of different versions of the same assembly at the same time
on the same machine. It gives us more control over the versioning of the assembly. When you strong name an
assembly, version number becomes a part of its identity, and thus we can register different version of the same
assembly in the GAC and execute them side by side.

How do you create a resource-only assembly?

One should create a resource only assembly if you need to update the resources frequently without recompiling
the whole solution.

Steps to create it are:


a. Create a new empty project.
b. Add a new resource item to the project.
c. In project's property pages, choose output type as class library..
d. Build project to have the resource files being compiled in an assembly.

Explain how to retrieve resources using ResourceManager class.

Use ResourceManager class to retrieve resources that exist in an assembly. Steps to do so are:

a. Create a reference to the assembly that has the resources.


b. Create an instance of ResourceManager.
c. Specify the base name of the resource file and provide the reference to the assembly that contains it.
d. Use the ResouceManager's GetObject or GetString method to retrive the resource.

e.g.:

Dim assembly As System.Reflection.Assembly


assembly = Me.GetType.Assembly
Dim myOtherAssembly As System.Reflection.Assembly
myOtherAssembly = System.Reflection.Assembly.Load("ResourceAssembly")

' Creates the ResourceManager.

Dim resourceManager As New _ 


System.Resources.ResourceManager("ResourceNamespace.myResources", _
assembly)

Dim resString As System.String


Dim resObj As System.Drawing.Image
resString = resourceManager.GetString("StringResource")
resObj = CType(resourceManager.GetObject("ImageResource"), _
System.Drawing.Image)

How do you install assembly to the Global Assembly Cache?

There are many ways:


a. Using Gacutil.exe:eg: gacutil -i MyLibrary.dll
b. Using Microsoft Windows installer 2.0.
c. Using Assembly Cache Viewer (Shfusion.dll)
d. Using the .NET Framework Configuration Tool (Mscorcfg.msc)

Explain how managed code slower than unmanaged code

Managed code not always is slower than unmanaged code. In managed code, the CLR does some optimization
for the way loops, subroutines should run and what is the best way to execute it.

Managed Code:-
Managed code is code written in one of over twenty high-level programming languages that are available for use
with the Microsoft® .NET Framework, including C#, J#, Microsoft Visual Basic® .NET, Microsoft JScript® .NET,
and C++. All of these languages share a unified set of class libraries and can be encoded into an Intermediate
Language (IL). A runtime-aware compiler compiles the IL into native executable code within a managed
execution environment that ensures type safety, array bound and index checking, exception handling, and
garbage collection.

By using managed code and compiling in this managed execution environment, you can avoid many typical
programming mistakes that lead to security holes and unstable applications. Also, many unproductive
programming tasks are automatically taken care of, such as type safety checking, memory management, and
destruction of unneeded objects. You can therefore focus on the business logic of your applications and write
them using fewer lines of code. The result is shorter development time and more secure and stable applications.

UnManaged Code
The Microsoft .NET Framework promotes interaction with COM components, COM+ services, external type
libraries, and many operating system services. Data types, method signatures, and error-handling mechanisms
vary between managed and unmanaged object models. To simplify interoperation between .NET Framework
components and unmanaged code and to ease the migration path, the common language runtime conceals from
both clients and servers the differences in these object models.

Code executing under the control of the runtime is called managed code. Conversely, code that runs outside the
runtime is called unmanaged code. COM components, ActiveX interfaces, and Win32 API functions are
examples of unmanaged code.

What are the options for stepping through code?

Show next statement


step into
step over
step out

Define Garbage collector in .NET.

GC is automatic memory reclamation. 


It is low-priority thread that always runs in the background of the  application. 
When memory is scarce, the priority of the garbage collector is elevated until sufficient resources are reclaimed.  
It is not certain when an object will be garbage collected. 

Define garbage collection.


GC is a low priority thread that runs in the background of the .Net application. It helps in destroying the objects
from the memory that are no longer in used.

--

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy