Sei sulla pagina 1di 9

1. What is an IL? A. MSIL stands for Microsoft Intermediate Language in short MSIL or IL(Intermediate Language).

When you compile a program the CLR will compile the code into MSIL code. Which will then be included in the assembly [exe/dll]? When you run the program in client place. The clr will manage to convert the MSIL into machine language by a process called Jitting. When we compile our .Net Program using any .Net compliant language like (C#, VB.NET, C+ +.NET) it does not get converted into the executable binary code but to an intermediate code, called MSIL or IL in short, understandable by CLR. MSIL is an OS and H/w independent code. When the program needs to be executed, this MSIL or intermediate code is converted to binary executable code, called native code. The presence of IL makes it possible the Cross Language Relationship as all the .Net compliant languages produce the similar standard IL code. 2. What is a CLR? A. CLR Stands For common language runtime. It is the implementation for CLI Common language implementation. The core run time engine in the Microsoft .Net framework for executing .net applications. The CLR Supplies Managed code with services such as cross language integration, code access security object life time management, resource management, type safety, pre-emptive threading, metadata services(type reflections) and debugging and profiling support. The most important part of the .NET Framework is the .Net Common Language Runtime (CLR) also called .Net Runtime in short. It is a framework layer that resides above the Operating System and handles/manages the execution of the .NET applications. Our .Net programs don't directly communicate with the Operating System but through CLR. 3. What is CTS? A. CTS stand for Common Type System. The CTS makes available a common set of data types so that compiled code of one language could easily interoperate with compiled code of another language by understanding each others data types. A fundamental part of the .NET Framework's Common Language Runtime (CLR), the CTS specifies no particular syntax or keywords, but instead defines a common set of types that can be used with many different language syntaxes. 4. What is a CLS (Common Language Specification)? A. Common Language Specification (CLS):The Common Language Specification (CLS) describes a set of features that different languages have in common. The CLS includes a subset of the Common Type System (CTS). 5. What is a Managed Code? A. By managed code, it means that the complete life cycle and execution is managed by the .NET Common Language Runtime (CLR). The .NET CLR manages the memory on behalf of the managed code, performs garbage collection on the managed heap, perform assembly validation and assembly (component) resolution on behalf of the program. The CLR also maintains the security constraints applied to the managed code Managed code is code that is written to target the services of the Common Language Runtime. In order to target these services, the code must provide a minimum level of information

(metadata) to the runtime. All C#, Visual Basic .NET, and JScript .NET code is managed by default. Visual Studio .NET C++ code is not managed by default, but the compiler can produce managed code by specifying a command-line switch (/CLR). 6. What is reflection? A. Refelction is the mechanism of discovering class information solely at run time. Reflection is the ability to read metadata at runtime. Using reflection, it is possible to uncover the methods, properties, and events of a type, and to invoke them dynamically. Reflection also allows us to create new types at runtime, but in the upcoming example we will be reading and invoking only. 7.What is concept of Boxing and Unboxing ? Boxing and unboxing is a essential concept in C#s type system. With Boxing and unboxing one can link between value-types and reference-types by allowing any value of a value-type to be converted to and from type object. Boxing and unboxing enables a unified view of the type system wherein a value of any type can ultimately be treated as an object. Converting a value type to reference type is called Boxing. Unboxing is an explicit operation. int i = 123; object o = i; // boxing in oops int i = 123; double o = convert.ToDouble(i); // boxing in .Net//

int i=123; double d=(double)(i);//unboxing int i=123; string a=i.Tostring();//unboxing 8. What are abstract classes? The abstract keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class. Classes can be declared as abstract by putting the keyword abstract before the class definition. For example: public abstract class A { // Class members here. } An abstract class cannot be instantiated. The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share. For example, a class library may define an abstract class that is used as a parameter to many of its functions, and require programmers using that library to provide their own implementation of the class by creating a derived class.

Abstract classes may also define abstract methods. This is accomplished by adding the keyword abstract before the return type of the method. For example: Abstract methods have no implementation, so the method definition is followed by a semicolon instead of a normal method block. Derived classes of the abstract class must implement all abstract methods. When an abstract class inherits a virtual method from a base class, the abstract class can override the virtual method with an abstract method. For example:

public class D { public virtual void DoWork(int i) { // Original implementation. } } public abstract class E : D { public abstract override void DoWork(int i); } public class F : E { public override void DoWork(int i) { // New implementation. } }

If a virtual method is declared abstract, it is still virtual to any class inheriting from the abstract class. A class inheriting an abstract method cannot access the original implementation of the methodin the previous example, DoWork on class F cannot call DoWork on class D. In this way, an abstract class can force derived classes to provide new method implementations for virtual methods. 9. What is a Interface? Interface is a contract that defines the signature of the functionality. So if a class is implementing a interface it says to the outer world, that it provides specific behavior. Example if a class is implementing IDisposable interface that means it has a functionality to release unmanaged resources. Now external objects using this class know that it has contract by which it can dispose unused unmanaged objects. Single Class can implement multiple interfaces. If a class implements a interface then it has to provide implementation to all its methods.

10. What is difference between abstract classes and interfaces? Abstract classes can have concrete methods while interfaces have no methods implemented. Interfaces do not come in inheriting chain, while abstract classes come in inheritance. 11. What types of validation controls are provided by ASP.NET? There are six main types of validation controls: RequiredFieldValidator - It checks whether the control have any value. Its used when you want the control should not be empty. RangeValidator - It checks if the value in validated control is in that specific range. Example txtCustomerCode should not be more than eight length. CompareValidator - It checks that the value in controls should match some specific value. Example Textbox TxtPi should be equal to 3.14. RegularExpressionValidator - When we want the control value should match with a specific regular expression. CustomValidator - It is used to define user-defined validation. ValidationSummary - It displays summary of all current validation errors. 12. What is the .Net namespaces used in Ado.Net? System.Data This namespace contains the basic objects used for accessing and storing relational data, such as DataSet, DataTable, and DataRelation. Each of these is independent of the type of data source and the type of the connection. System.Data.OleDB:It contains the objects that we use to connect to a data source via an OLE-DB provider, such as OleDbConnection, OleDbCommand, etc. These objects inherit from the common base classes, and so have the same properties, methods, and events as the SqlClient equivalents. System.Data.SqlClient: This contains the objects that we use to connect to a data source via the Tabular Data Stream (TDS) interface of Microsoft SQL Server (only). This can generally provide better performance as it removes some of the intermediate layers required by an OLE-DB connection. System.XML: This Contains the basic objects required to create, read, store, write, and manipulate XML documents according to W3C recommendations. What are three main function of SQLCommand object and their uses ? It is used to connect connection object to DataReader or DataSet. Following are the methods provided by command object : ExecuteNonQuery : Executes the command defined in the CommandText property against the connection defined in the Connection property for a query that does not return any row (an UPDATE, DELETE or INSERT). Returns an Integer indicating the number of rows affected by the query. Sqlcommand cmd=new sqlcommand(query,con); Int i= cmd. ExecuteNonQuery();
13.

ExecuteReader : Executes the command defined in the CommandText property against the connection defined in the Connection property. Returns a "reader" object that is connected to the resulting rowset within the database, allowing the rows to be retrieved. Sqlcommand cmd=new sqlcommand(query,con); Sqldatareader dr= cmd.ExecuteReader();

ExecuteScalar : Executes the command defined in the CommandText property against the connection defined in the Connection property. Returns only single value (effectively the first column of the first row of the resulting rowset) any other returned columns and rows are discarded. It is fast and efficient when only a single value is required Sqlcommand cmd=new sqlcommand(query,con); Sqldatareader dr= cmd. ExecuteScalar (); 14. What is Constructors and its types in C#. Constructors are class methods that are executed when an object of a class or struct is created. They have the same name as the class or struct, and usually initialize the data members of the new object. A class or struct may have multiple constructors that take different arguments. Constructors enable the programmer to set default values, limit instantiation, and write code that is flexible and easy to read.If you do not provide a constructor for your object, C# will create one by default that instantiates the object and sets member variables to the default values Constructors Types: 1. Default Constructor: A constructor that takes no parameters is called a default constructor. Default constructors are invoked whenever an object is instantiated by using the new operator and no arguments are provided to new public class Taxi { public bool isInitialized; public Taxi() { } } Taxi t=new Taxi ();// creating object of class taxi. 2. Parametrized Contructor: which takes some parameters and initialize the data members using that argumemts public class Taxi { public bool b; public Taxi( bool b1) { b=b1; } } Bool a=true;0//create object of class

Taxi t=new taxi (a); // 3. Static constructors: A static constructor is used to initialize any static data, or to perform a particular action that needs to be performed once only. It is called automatically before the first instance is created or any static members are referenced. Static constructors have the following properties:
A static constructor does not take access modifiers or have parameters. A static constructor is called automatically to initialize the class before the first instance

is created or any static members are referenced. A static constructor cannot be called directly. The user has no control on when the static constructor is executed in the program. A typical use of static constructors is when the class is using a log file and the constructor is used to write entries to this file. class SimpleClass { // Static variable that must be initialized at run time. static readonly long baseline; // Static constructor is called at most one time, before any // instance constructor is invoked or member is accessed. static SimpleClass() { baseline = DateTime.Now.Ticks; } } 4.Private Constructor: A private constructor is a special instance constructor. It is generally used in classes that contain static members only. If a class has one or more private constructors and no public constructors, other classes (except nested classes) cannot create instances of this class. For example: Syntax: class NLog { // Private Constructor: private NLog() { } public static double e = Math.E; //2.71828... } The following is an example of a class using a private constructor. public class Counter {

private Counter() { } public static int currentCount; public static int IncrementCount() { return ++currentCount; } } class TestCounter { static void Main() { // If you uncomment the following statement, it will generate // an error because the constructor is inaccessible: // Counter aCounter = new Counter(); // Error Counter.currentCount = 100; Counter.IncrementCount(); Console.WriteLine("New count: {0}", Counter.currentCount); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadLine(); } } // Output: New count: 101 Copy Constructor: the Person class contains a constructor that takes as its argument another object of type Person. The contents of the fields in this object are then assigned to the fields in the new object. An alternative copy constructor sends the name and age fields of the object to be copied to the instance constructor of the class. class Person { private string name; private int age; // Copy constructor. public Person(Person previousPerson) { name = previousPerson.name; age = previousPerson.age; } //// Alternate copy contructor calls the instance constructor. //public Person(Person previousPerson) // : this(previousPerson.name, previousPerson.age) //{ //} // Instance constructor.

public Person(string name, int age) { this.name = name; this.age = age; } // Get accessor. public string Details { get { return name + " is " + age.ToString(); } } } class TestPerson { static void Main() { // Create a new person object. Person person1 = new Person("George", 40); // Create another new object, copying person1. Person person2 = new Person(person1); Console.WriteLine(person2.Details); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadLine(); } } // Output: George is 40 15. What is sealed Classe? Classes can be declared as sealed by putting the keyword sealed before the class definition. For example:

public sealed class D { // Class members here. }

A sealed class cannot be used as a base class. For this reason, it cannot also be an abstract class. Sealed classes prevent derivation. Because they can never be used as a base class, some run-time optimizations can make calling sealed class members slightly faster. A class member, method, field, property, or event, on a derived class that is overriding a virtual member of the base class can declare that member as sealed. This negates the virtual aspect of the member for any further derived class. This is accomplished by putting the sealed keyword before the override keyword in the class member declaration. For example: public class D : C { public sealed override void DoWork() { } } 16. What Is Connection Strings?

SQLConnection con; Con= new sqlconnection(Data Source=SERVER NAME; Initial Catalog=Database Name; Integrated Security=true);

Potrebbero piacerti anche