C# Interview Quesss

Share Embed Donate


Short Description

This is my collection from different sites for c# users....

Description

C# Interview Questions And Answers Page 1 Ques: 1 what is partial class in .net 2.0 Ans: Single Class can be separated into multiple physical files with same logical name. Ans: Partial Class:-Using the partial keyword indicates that other parts of the class, struct, or interface can be defined within the namespace

Below is the example of a partial class. Listing 1: Entire class definition in one file (file1.cs) public class Node { public bool Delete() { } public bool Create() { } } Listing 2: Class split across multiple files (file1.cs) public partial class Node { public bool Delete() { } } (file2.cs) public partial class Node { public bool Create() { } }

Ques: 2 I want to delete an dll with a newer version, but nothing it throws an UnauthorizedAccessException!

please help!!!

Assembly a = Assembly.LoadFile(source); Assembly b = Assembly.LoadFile(des Ans: a Ques: 3 Ans: Hi there, i have been programming for a few weeks now, i am still learning new things as i go on. i would like to understand a few more things about c# if anyone can answer my questions i would be more then appreciated. - What is the rule i must consider before placing a semi-colon? - What is the best data type to use to hold a value of 1200.0? and is there any other data types that could be used and why should i choose the other. - What is the defence between = and ==? And do i need to use both? - What is the defrence between a while and a do-while loop? - What is a class? And why is it so important to be used? Ques: 4 What is server code and client code in C#? Ans: Code which execute on client are called client side code Otherwise Server side code. Ans: Server code is run on server side and client code is run client side. Ans: Server side code will execute at server end all the business logic will execute at server end where as client side code will execute at client side at browser end. Ques: 5 Why we using in header file using system and more header file is in C# what is difference between and all header file ? Ques: 6 Give Real life examples of polymorphisms, encapsulation and inheritance? Ans: real lif example of inheritance is parent child relationship Ques: 7 What is partial class?what is its advantage. Ans: Partial Class: when a class need to be implemented at multiple locations with same class name then those classes need to be declared as "partial". Example: public main() { class Test {

------------} class Test //error { ------------} } public main() { partial class Test { ------------} partial class Test //correct { ------------} } Ques: 8 What is the name of c#.net compiler? Ans: csc Ans: .cs Comliler Ans: Name of c# .net compiler is CSC. CSC stands foe C SHARP COMPILER. Ans: Just In time (JIT) Compiler....!! Ans: JIT Just In Time Compiler act as interface between IDE to OS after Common run time compilation is done Ques: 9 What is an object? Ans: Object:-Object is the basic run time entity. The object type is based on System.Object in the .NET Framework. You can assign values of any type to variables of type object. All data types, predefined and user-defined, inherit from the System.Object class. The object data type is the type to and from which objects are boxed. Exapmle:class a {}

public static void Main() { a ob= new a();// create object ob of class a; } Ques: 10 What is a class? Ans: Class:Classes are declared using the keyword class. The declaration takes the form: [attributes] [modifiers] class identifier [:base-list] { class-body }[;] where: attributes (Optional) :-Additional declarative information. modifiers (Optional):The allowed modifiers are new, abstract, sealed, and the four access modifiers. identifier:The class name. base-list (Optional) :-A list that contains the one base class and any implemented interfaces, all separated by commas. class-body :-Declarations of the class members. Example:Public class a { // some members and parameter } Ques: 11 what abstraction,encapsulation,inheritance? Define with example. Ans: Abstraction:-Abstraction is the process of hiding the details and exposing only the essential features of a particular concept or object. Abstraction is another good feature of OOPS. Abstraction means to show only the necessary details to the client of the object Example:-A simple example is using a base class "Animal", with a virtual function "Walk". In the case two-legged versus four-legged animals, both of them walk, but the actual mechanics are different. The "Walk" method abstracts the actual mechanics behind the walking that each "Animal" does. 2nd example:-A class called Animal. It has properties like ears,colour, eyes but they are not defined. It has methods like Running(), Eating(), etc. but the method does not have any body, just the definition. Encapsulation:-Encapsulation is the term given to the process of hiding all the details of an object that do not contribute to its essential characteristics.its wrapping of data and members in a single unit.Encapsulation is a process of hiding all the internal details of an object from the outside world . 1:- Encapsulation is the ability to hide its data and methods from outside the world and only expose data and methods that are required . 2.Encapsulation gives us maintainability, flexibility and extensibility to our code.

3.Encapsulation provides a way to protect data from accidental corruption . 4.Encapsulation gives you the ability to validate the values before the object user change or obtain the value . 5.Encapsulation allows us to create a "black box" and protects an objects internal state from corruption by its clients. 6.Encapsulation is the technique or process of making the fields in a class private and providing access to the fields using public methods. Example:-cars and owners... all the functions of cars are encapsulated with the owners.. No one else can access it... Inheritance:-In object-oriented programming (OOP), Inheritance is a way to compartmentalize and reuse code by creating collections of attributes and behaviors called objects which can be based on previously created objects. In classical inheritance where objects are defined by classes. classes can inherit other classes. The new classes, known as Sub-classes (or derived classes), inherit attributes and behavior of the pre-existing classes, which are referred to as Super-classes. the process of deriving one class from parent class called . Example:-INHERITANCE MEANS A CHILD CLASS USE THE ALL THE ELEMENTS IN THE PARENTS CLASS. DAD | CHILED Seccond Example:Kingfisher jet ^ | Airplane ^ | Flying Things Ques: 12 What is mean "Death of Diamod"? Ans: Death Diamond:-In object-oriented programming languages with multiple inheritance and knowledge organization, the diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If a method in D calls a method defined in A (and does not override the method), and B and C have overridden that method differently, then from which class does it inherit: B, or C? For example a class Button may inherit from both classes Rectangle (for appearance) and Clickable (for functionality/input handling), and classes Rectangle and Clickable both inherit from the Object class. Now if the equals method is called for a Button object and there is no such method in the Button class but there is an overridden equals method in both Rectangle and Clickable, which method should be eventually called? ihis is called "Death of Diamond". Ex: Class a { } class b: a

{} class c: a {} class d:b,c {} It is called the "diamond problem" because of the example of the class inheritance in this situation. In this example, class A is at the top, both B and C separately inherit to A, and D inherits both...... Ques: 13 what is the main difference between delegate and an event in c#? Ans: Delegate:-A delegate is basically a reference to a method. A delegate can be passed like any other variable. This allows the method to be called anonymously, without calling the method directly. delegate declaration 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. The delegate declaration takes the form: [attributes] [modifiers] delegate result-type identifier ([formal-parameters]) Event:-An event in one program can be made available to other programs that target the .NET runtime. An event is a member that enables an object or class to provide notifications. Clients can attach executable code for events by supplying event handlers. Events are declared using event-declarations: event-declaration: event-field-declaration event-property-declaration event-modifier: new public protected internal private static Example:public delegate void EventHandler(object sender, Event e); public class Button: Control { public event EventHandler Click; protected void OnClick(Event e) { if (Click != null) Click(this, e); } public void Reset() { Click = null; } } Ques: 14 How to use Hash Table,ArrayList in c# ?Explain with example.

Ans: ArrayList:-Arraylist is a collection of objects(may be of different types). Arraylist is very much similar to array but it can take values of different datatypes. If you want to find something in a arraylist you have to go through each value in arraylist, theres no faster way out.ArrayList's size can be changed dynamically. Items are added to the ArrayList with the Add() method. example:-HOW TO ADD DATA IN ARRAYLIST: using System.Collections; class Program { static void Main() { // // Create an ArrayList and add three elements. // ArrayList list = new ArrayList(); list.Add("One"); list.Add("Two"); list.Add("Three"); } } EXAMPLE-Adding one ArrayList to second one There are different ways to add one ArrayList to another, but the best way is using AddRange. Internally, AddRange uses the Array.Copy or CopyTo methods, which have better performance than some loops. === Program that uses Add and AddRange === using System; using System.Collections; class Program { static void Main() { // // Create an ArrayList with two values. // ArrayList list = new ArrayList(); list.Add(15); list.Add(17); // // Second ArrayList. // ArrayList list2 = new ArrayList(); list2.Add(110); list2.Add(113); // // Add second ArrayList to first. //

list.AddRange(list2); // // Display the values. // foreach (int i in list) { Console.WriteLine(i); } } } === Output of the program === 15 17 110 113 The ArrayList class provides the Count property, which is a virtual property. When you use Count, no counting is actually done; instead, a cached field value is returned HASH TABLE:-Hashtable is also collection which takes a key corresponding to each values. If you want to find something in a hashtable you dont have to go through each value in hashtable, instead search for key values and is faster.The Hashtable lets you quickly get an object out of the collection by using it's key. The Hashtable object contains items in key/value pairs. The keys are used as indexes. We can search value by using their corresponding key. The data type of Hashtable is object and the default size of a Hashtable is 16. Items are added to the Hashtable with the ADD()method. Example-How to add data in hash table:-Add method of Hashtable is used to add items to the hashtable. The method has index and value parameters. The following code adds three items to hashtable. hshTable .Add("A1", "Kamal"); hshTable .Add("A2", "Aditya"); hshTable .Add("A3", "Ashish"); Retrieving an Item Value from Hashtable The following code returns the value of "Author1" key: string name = hshTable["A1"].ToString(); Removing Items from a Hashtable The Remove method removes an item from a Hashtable. The following code removes item with index "A1" from the hashtable: hshTable.Remove("A1");

Looking through all Items of a Hashtable The following code loops through all items of a hashtable and reads the values. // Loop through all items of a Hashtable IDictionaryEnumerator en = hshTable.GetEnumerator(); while (en.MoveNext()) { string str = en.Value.ToString(); } Ques: 15 What is the difference between shadow and override ? Ans: Difference between shadow and override:Shadowing hide the inherrited method using new keyword and CLR choose the target mthod between the parent and child to call using the object's runtime type.Overriding hide the inherrited method using override keyword and the parent should be virtual. overrding always choose the object's compile-time type. Differences:1-PorPose:SHADOW-Protecting against a subsequent base class modification introducing a member you have already defined in your derived class. OVERRIDE-Achieving polymorphism by defining a different implementation of a procedure or property with the same calling sequence 2-Redefined element:SHADOW:-Any declared element type. OVERRIDE:-Only a procedure (Function or Sub) or property 3-Accessibility:SHADOW:-Any accessibility OVERRIDE:-Cannot expand the accessibility of overridden element (for example cannot override Protected with Public) 4-Readability and writability SHADOW:-Any combination OVERRIDE:-Cannot change readability or writability of overridden property 5-Keyword usage SHADOW:-Shadows recommended in derived class; Shadows assumed if neither Shadows nor Overrides specified. OVERRIDE:-Overridable required in base class; Overrides required in derived class Ques: 16 What is the top .NET class that everything is derived from? Ans: System.Object Ques: 17 When we can inherit a protected class-level variable? Ans: Classes in the same namespace. Ques: 18 Does C# support multiple inheritance? Ans: No directly,but we can use interface for multiple inheritence Ans: No directly,but we can use interface for multiple inheritence Ques: 19 How do you inherit from a class in C#?

Ans: Place a colon and then the name of the base class. exmple:class a {} class b: a //inherit class a {} Ques: 20 What is an abstract class? Ans: Abstract class:-Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes. Abstract classes have the following features: 1-An abstract class cannot be instantiated. 2-An abstract class may contain abstract methods and accessors. 3-It is not possible to modify an abstract class with the sealed modifier, which means that the class cannot be inherited. 4-A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors. Abstract class have complete and non complete member and methods. Example:- abstract class a { int a; public abstract void print(); }

C# Interview Questions And Answers Page 2 Ques: 21 What does the keyword virtual mean in the method definition? Ans: It means that the subclasses( inheriting classes) can override the method. Ques: 22 How's method overriding different from overloading? Ans: Difference between overriding and overloading:1:-When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class. 2:-overriding keyword cahnge behavour in derive class with same signature Overloading means same name but passing different datatype or different number arguments within the same class 3:-Method overloading means same method name but different parameters. Method overriding means same method name and parameters also same. In method overloading method will differentiate with parameters name and in method overriding method will differentiate with method signature Ques: 23 Describe the accessibility modifier protected internal.

Ans: protected internal:-Access is limited to the current project or types derived from the containing class.Access limited to the current project. Ques: 24 Are private class-level variables inherited? Ans: Yes, but they are not accessible Ques: 25 When you inherit a protected class-level variable? Who is it available to? Ans: Protected members can be accessible by all the derived class irrespective of the Namespaces only protected Friend or protected internal will be accessed inside the namespace Ques: 26 What's the implicit name of the parameter that gets passed into the class' set method? Ans: Value, and its datatype depends on whatever variable we're changing Ques: 27 Is it mandatory to implement all the methods which are there in abstract class if we inherit that abstract class? Ans: yes,It is mandatory to implement all the methods which are there in abstract class if we inherit that abstract class? Ques: 28 What is the difference between const and static read-only? Ans: The difference is that static read-only can be modified by the containing class, but const can never be modified and must be initialized to a compile time constant. To expand on the static read-only case . The Constant Fields are those which cannot be changed in runtime. Its value has to be assigned at declaration time. const string strMyString="Constant Data" ; //This is valid.Once declared now the value cannot be reassigned strMyString="Changed Data" ... Ques: 29 How to fill datalist usinf XML file and how to bind it,code behind language is c# ? Ques: 30 What is advantase of serialization? Ans: SERIALIZATION:-serialization is the process of maintaing object in the form stream.it is useful in case of remoting. 2.Serialization is the process of converting object into byte stream which is useful to transport object(i.e remoting) persisting object(i.e files database) 3.SERIALIZATION IS PROCESS OF LODING THE OBJECT STATE IN THE FORM OF BYTE STREAMS IN DATABASE/FILE SYATEM. 4.Serialization in .NET allows the programmer to take an instance of an object and convert it into a format that is easily transmittable over the network or even stored in a database or file system. This object will actually be an instance of a custom type including any properties or fields you may have set 5.using Serialization instead of DataInput/DataOutput streams has a major impact on versioning . Serialization keeps a lot of metadata in the stream. This makes detecting format changes very easy, but can really complicate backward compatibility.Also,serialization is geared toward preserving the connections of an object graph, which is behind a lot of the differences you mentioned. Ques: 31 How we handle sql exceptions? Ans: SqlExceptionclass is created whenever the .NET Framework Data Provider for SQL Server

encounters an error generated from the server. (Client side errors are thrown as standard common language runtime exceptions.) SqlException always contains at least one instance of SqlError. ... try { myCommand.Connection.Open(); } catch (SqlException e) { string errorMessages ; for (int i 0; i < e.Errors.Count; i++) { errorMessages + Index # + i + \n + Message: + e.Errors[i].Message + \n + LineNumber: + e.Errors[i].LineNumber + \n + Source: + e.Errors[i].Source + \n + Procedure: + e.Errors[i].Procedure + \n ; } System.Diagnostics.EventLog log new System.Diagnostics.EventLog(); log.Source My Application ; log.WriteEntry(errorMessages); Console.WriteLine( An exception occurred. Please contact your system administrator. ); } Ques: 32 What is the class that handles SqlServer exceptions? Ans: Ans: SqlExceptionclass is created whenever the .NET Framework Data Provider for SQL Server encounters an error generated from the server. (Client side errors are thrown as standard common language runtime exceptions.) SqlException always contains at least one instance of SqlError. Ques: 33 What is indexer? Ans: Indexer:-Indexers permit instances of a class or struct to be indexed in the same way as arrays. Indexers are similar to properties except that their accessor take parameters. Indexers allow you to index a class or a struct instance in the same way as an array. To declare an indexer, use the following declaration: [attributes] [modifiers] indexer-declarator {accessor-declarations} The indexer-declarator takes one of the forms: type this [formal-index-parameter-list] type interface-type.this [formal-index-parameter-list] The formal-index-parameter takes the form: [attributes] type identifier where:

attributes (Optional) :Additional declarative information. For more information on attributes and attribute classes, modifiers (Optional) :Allowed modifiers are new and a valid combination of the four access modifiers. indexer-declarator :Includes the type of the element introduced by the indexer, this, and the formal-indexparameter-list. If the indexer is an explicit interface member implementation, the interfacetype is included. formal-index-parameter-list:Specifies the parameters of the indexer. The parameter includes optional attributes, the index type, and the index identifier. At least one parameter must be specified. The parameters out and ref are not allowed. accessor-declarations :The indexer accessors, which specify the executable statements associated with reading and writing indexer elements. The get Accessor:The get accessor body of an indexer is similar to a method body. It returns the type of the indexer. The get accessor uses the same formal-index-parameter-list as the indexer. For example: get { return myArray[index]; } The set Accessor:The set accessor body of an indexer is similar to a method body. It uses the same formalindex-parameter-list as the indexer, in addition to the value implicit parameter. For example: set { myArray[index] = value; } Ques: 34 where indexer is used ? Ans: indexer member, which itself contains a get accessor and a set accessor. These accessors are implicitly used when you assign the class instance elements in the same way as you can assign elements in an array. The indexer provides a level of indirection where you can insert bounds-checking, and in this way you can improve reliability and simplicity with indexers. Ques: 35 Can we inherit the java class in C# class?If Yes then how? Ans: yes,with the help of .dll of java class we can inherit the java class in c# Ques: 36 Every statement in C# must end with? Ans: every statement in c sharp must end with semi colon.it indicates statement completed Ques: 37 The C# code files have an extension ? Ans: C# code files have .cs exrension. Ques: 38 How you can compile a C# program using command promt?

Ans: We can compile a c# program using command promt such as :-csc filename Ques: 39 ASP.NET web pages can be programmed in C#? Ans: yes. ASP .NET web pages can be programmed in C# Ques: 40 All the .NET languages have the following in common? Ans: All the .NET languages have the following in common 1-Base class library

C# Interview Questions And Answers Page 3 Ques: 41 IL code compiles to ? Ans: Il compiles to native code Ques: 42 Which is the first level of compilation in the .NET languages? Ans: The first level of compilation in the .NET languages is source code convert into msil(Microsoft Intermediate language code which is generated by the C# compiler Ques: 43 What is IL? Ans: IL:-stands for Intermediate Language.This is the language code generated by the C# compiler or any .NET-aware compiler. All .NET languages generate this code. This is the code that is executed during runtime.You can view this MSIL code with the help of a utility called Intermediate Language Disassembler (ILDASM). This utility displays the application's information in a tree-like fashion. Because the contents of this file are read-only, a programmer or anybody accessing these files cannot make any modifications to the output generated by the source code. Ques: 44 What is CTS? Ans: CTS:-CTS stands for Common Type System. 1-Common Type System is also a standard like cls. If two languages (c# or vb.net or j# or vc++) wants to communicate with each other, they have to convert into some common type (i.e in clr common language run time). In c# we use int which is converted to Int32 of CLR to communicate with vb.net which uses Integer or vice versa. 2-The Common Type System defines how types are declared, used, and managed in the runtime, and is also an important part of the runtime's support for cross-language integration. 3.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. Ques: 45 What is the namespace used for Reflection? Ans: System.Reflection is used for Reflection Ques: 46 To access attributes, the waht is used? Ques: 47 List all collections in C#. Ans: CSharp Collections are data structures that holds data in different ways for flexible

operations . C# Collection classes are defined as part of the System.Collections or System.Collections.Generic namespace. Most collection classes implement the same interfaces, and these interfaces may be inherited to create new collection classes that fit more specialized data storage needs. collections are:1-C# ArrayList Class 2-Hash Table 3-Stack 4-Queue etc Ques: 48 How you can write Unsafe code in C# and in which block? Ques: 49 Which method is used to force the garbage collector? Ans: System.GC.Collect() Ques: 50 Each process in a 32 bit Windows environment has the what amount of virtual memory will available? Ques: 51 What is correct syntax for defining a delegate? Ans: Correct syntax for defining a delegate:[attributes] [modifiers] delegate result-type identifier ([formal-parameters]); where: attributes (Optional):Additional declarative information. For more information on attributes and attribute classes, modifiers (Optional) :The allowed modifiers are new and the four access modifiers. result-type :The result type, which matches the return type of the method. identifier :The delegate name. formal-parameters (Optional):Parameter list. Example:public delegate int delsum(int x,int y); Ques: 52 What is syntax of inherit a class? Ans: Syntax of inherit a class:Public class a { // some member and methods } class b:a // b class inherit a class { } Ques: 53 How do you deploy an assembly? Ans: Assembly:-There are several ways to deploy an assembly into the global assembly cache: 1) Use an installer designed to work with the global assembly cache. This is the preferred option for installing assemblies into the global assembly cache.

2) Use a developer tool called the Global Assembly Cache tool (Gacutil.exe)provided by the .NET Framework SDK. 3) Use Windows Explorer to drag and drop assemblies into the cache. Ans: there are following way to deploy an assembly:An MSI installer, a CAB archive, and XCOPY command. Ques: 54 How namespace is used for globalization? Ans: The System.Globalization namespace holds all culture and region classes to support different date formats, different number formats, and even different calendars that are represented in classes such as GregorianCalendar, HebrewCalendar, JapaneseCalendar, and so on. By using these classes, you can display different representations depending on the user’s locale. Ques: 55 How does a running application communicate or share data with other application running in different application domains? Ans: If a running application does need to communicate or share data with other application running in different application domains,it must do by calling by on .NETs Remoting Services Ques: 56 What are difference between shadow and override? Ques: 57 We have an event handler called MyEvent and we want to link the click event of control, MyButton, to use MyEvent, what is the code that will like them together? Ans: If we have an event handler called MyEvent and we want to link the click event of control, MyButton, to use MyEvent, Then code will be:control.Click += new EventHandler(MyEvent); Ques: 58 Which debugging window allows you to see the methods called in the order they were called? Ans: The Call Stack window allows you to see the methods called in the order they were called. Ques: 59 The auto,local ,watch Ans: The Call Stack window allows you to see all the name and values of all the variables in scope Ques: 60 What is wrapper class? Is it available in c#? Ans: Wrapper class:-Wrapper class are those class in which we cant define and call all predefined functiuon.Wrapper Classes are the classes that wrap up the primitive values in to a class that offer utility method to access it . For eg you can store list of int values in a vector class and access the class. Also the methods are static and hence you can use them without creating an instance . The values are immutable .

Page 4 Ques: 61 What is protected internal class in C# ? Ans: Protected Internal:-Access is limited to the current project or types derived from the containing class. 2-The item is visible to any code within its containing assembly and also to any code inside a derived type

Ques: 62 Which keyword is used of specify a class that cannot inherit by other class? Ans: By using "Sealed " keyword Ques: 63 Can we create the instance for abstract classes? Ans: NO,we cant create the instance for absract classes Ans: no,we cannot create instance for abstract class but we can create reference for abstract class.A reference doesnotcontain its own memory like object when it is created, but shares the memory of the class. we can create an object for derived class.we can use this object to call the methods Ques: 64 Can we use Friend Classes or functions in C#? Ans: no ,we can not use friend classes or function in c# Ques: 65 How we can use inheritance and polymorphisms in c# programming? Ques: 66 How to find exceptions in database?Give examples . Ans: To find Exceptions in database:-Framework is endowed with provider specific exception class that we can use to handle exceptions from database. For example instance to handle exceptions from sqlserver we can use System.Data.SqlClient.SqlException class. Ques: 67 How can objects be late bound in .NET? Ans: Using Late Bound COM Objects Ques: 68 Where we can use DLL made in C#.Net? Ans: Supporting .Net, because DLL made in C#.Net semi compiled version. It’s not a com object. It is used only in .Net Framework As it is to be compiled at runtime to byte code. Ques: 69 What Datatypes does the RangeValidator Control support? Ans: There are following data types that support Range validator control:1-Integer 2-Date 3-String 4-Double 5-Currency Ques: 70 Constructor is the method which is implicitly created when ever a class is instantiated. Why? Ans: The default constructor is called automatically when ever a class is instantiated. Ques: 71 Why multiple Inheritance is not possible in C#? Ans: multiple inheritance is possible through interface Ques: 72 Why strings are immutable? Ans: In .NET, strings are immutable. This means that, once a value is assigned to a String object, it can never be changed. Ques: 73 This is a Regular expression built for parsing string in vb.net and passed to Regex class. Dim r As Regex = New

Regex(",(?=([^""]*""[^""]*"")*(?![^""]*""))") What is C# equivalent for this regular exp Ans: C# equivalent is : System.Text.RegularExpressions.Regex myRegex new Regex (" ( ([^""]*""[^""]*"")*(?![^""]*""))"); Ques: 74 How to convert ocx into DLL ? Ans: use the aximp.exe provided with the .NET framework. It stands for Microsoft .NET ActiveX Control to Windows Forms Assembly Generator. Generates a Windows Forms Control that wraps ActiveX controls defined in the OcxName. Ques: 75 What is the main difference between pointer and delegate with examples? Ans: The difference between pointer and delegate:Delegate:-A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked. Unlike function pointers in C or C++, delegates are object-oriented, type-safe, and secure. Example:using System; delegate void MyDelegate(string s); class MyClass { public static void Hello(string s) { Console.WriteLine(" Hello, {0}!", s); } public static void Goodbye(string s) { Console.WriteLine(" Goodbye, {0}!", s); } public static void Main() { MyDelegate a, b, c, d; a = new MyDelegate(Hello); b = new MyDelegate(Goodbye); c = a + b; // Compose two delegates to make another d = c - a; // Remove a from the composed delegate Console.WriteLine("Invoking delegate a:"); a("A"); Console.WriteLine("Invoking delegate b:"); b("B"); Console.WriteLine("Invoking delegate c:"); c("C"); Console.WriteLine("Invoking delegate d:"); d("D"); } }

Output Invoking delegate a: Hello, A! Invoking delegate b: Goodbye, B! Invoking delegate c: Hello, C! Goodbye, C! Invoking delegate d: Goodbye, D! Code Discussion Pointer:-C# statements execute in either a safe or an unsafe context. Safe context is the default, but any code using pointers requires unsafe context. unsafe:- Specifies unsafe context. Once you have a pointer to a variable, you must ensure that the variable isn't moved in memory by the garbage collector. pointer holds reference to a variable or pointer is a variable which holds the address of another variable. Example:using System; class UnsafeTest { // unsafe method: takes pointer to int unsafe static void SquarePtrParam (int* p) { *p *= *p; } public static void Main() { int i = 5; // unsafe statement for address-of operator unsafe SquarePtrParam (&i); Console.WriteLine (i); } } Output 25 Ques: 76 What is object pooling ? Ans: Object pooling :- Object pooling is a COM+ Service that enables to reduce the overhead of creating each object from scratch, Object pooling is a well known technique to minimize the creation of objects that can take a significant amount of time. Common examples are to create a pool of database connections such that each request to the database can reuse an existing connection instead of creating one per client request.Threads are also another common candidate for pooling in order to increase responsiveness of an application to multiple concurrent client requests. Ques: 77 How do i read the information from web.config file? Ans: connection cn=System.Configuration.ConfigurationManeger.Appsetting(variable name) in 2005 Ques: 78 What is the default Function arguments?

Ans: C# does not support optional arguments. Ques: 79 What is XML Schema? Ans: Ans: XML Schema:-The aim of an XML Schema is to define the legal building blocks of an XML document, just like a DTD.XML Schema is an XML-based alternative to DTD.An XML schema describes the structure of an XML document.The XML Schema language is also referred to as XML Schema Definition (XSD). XML Schema defines elements that can appear in a document. XML Schema defines attributes that can appear in a document XML Schema defines which elements are child elements XML Schema defines the order of child elements XML Schema defines the number of child elements XML Schema defines whether an element is empty or can include text XML Schema defines data types for elements and attributes. XML Schema defines default and fixed values for elements and attributes Ques: 80 How can we check whether a dataset is empty or not in C#.net Ans: To check whether a dataset is empty or not in C#.net:bool IsEmpty(DataSet dataSet) { foreach(DataTable table in dataSet.Tables) if (table.Rows.Count != 0) return false; return true; } Ques: 81 Is it possible to inherit a class that has only private constructor? Ans: No,Its not possible to inherit a class that has only private constructor. Ques: 82 How do you choose 1 entry point when C# project has more Main( ) method? Ans: If project has more Main()method:CSC /main:classname filename.cs Ques: 83 What is C# reserved keyword ?Give List. Ans: Keyword:-C# has a number of built in keywords. Keywords are predefined reserved identifiers that have special meanings to the compiler. They cannot be used as identifiers in your program unless they include @ as a prefix. List of Reserved Keyword:abstract, enum ,long, stackalloc , as, event ,namespace ,static, base ,explicit, new, string, bool, extern ,null, struct, break ,false ,object, switch, byte, finally, operator, this, case, fixed, out, throw, catch, float, override ,true char ,for, params ,try , checked ,foreach, private, typeof,

class, goto ,protected ,uint, const, if, public ,ulong, continue, implicit ,readonly, unchecked, decimal ,in ,ref, unsafe , default, int ,return ,ushort, delegate ,interface ,sbyte, using do, internal, sealed ,virtual double ,is, short, void else ,lock ,sizeof, while Ques: 84 Sealed class can be inherited ?Yes/No Ans: NO,Sealed classes cant be inherited Ques: 85 It is not permitted to declare modifier on the members in an interface definition? Ans: yes.It is not permitted to declare modifier on the members in an interface definition. By default all the members in an Interface definition are public so there is no need to declare access modifier public. It would be a compile time error otherwise Ques: 86 How Interface members can be declare ? Ans: Interface:-The interface keyword declares a reference type that has abstract members. The interface declaration takes the form: [attributes] [modifiers] interface identifier [:base-list] {interface-body}[;] where: attributes (Optional):Additional declarative information. modifiers (Optional) :The allowed modifiers are new and the four access modifiers. identifier :The interface name. base-list (Optional) :A list that contains one or more explicit base interfaces separated by commas. interface-body :Declarations of the interface members. example:public interface A { void show(string s); } public interface b { void get(string s); } class d: a,b

{ } Ques: 87 Which method is implicitly called when an object is created ? Ans: constructor will call when an object is created Ques: 88 Constructors can not be static?Yes/NO Ans: NO,Constructors can be static. Ques: 89 Which preprocessor directive are used to mark that contain block of code is to be treated as a single block? Ques: 90 How are the attributes specified in C# ? Ans: Attributes:-Attributes are elements that allow you to add declarative information to your programs. This declarative information is used for various purposes during runtime and can be used at design time by application development tools. Attributes are generally applied physically in front of type and type member declarations. They're declared with square brackets, "[" and "]", surrounding the attribute such as the following ObsoleteAttribute attribute: Ques: 91 For performing repeated modification on string which class is preferred? Ques: 92 In order to use stringbuilder in our class we need to refer?? Ans: using System.Text; Ques: 93 Gives the a member of stringbuilder. Ques: 94 Which method is actually called ultimately when Console.WriteLine( ) is invoked? Ans: AppendFormat() method is actually called ultimately when Console.WriteLine( ) is invoked? Ques: 95 What happens when you create an arraylist as ArrayList Arr=new ArrayList()? Ans: when you create an arraylist as ArrayList Arr=new ArrayList() then an arraylist of object Arr is created with the capacity of 16 Ques: 96 What is the output of Vectors.RemoveAt(1)? Ans: The output of Vectors.RemoveAt(1):-Removes the object at position 1 Ques: 97 GetEnumerator( ) of Ienumerable interface returns ? Ans: GetEnumerator( ) of Ienumerable interface Returns an enumerator that iterates through a collection. Ques: 98 How do you add objects to hashtable in c#? Ans: With the help of ADD()method we can add objects to hashtablein c# Ques: 99 If A.equals(B) is true then A.getHashcode & B.getHashCode must always return same hash code in c#? Ans: Flase because it is given that A.equals(B) returns true i.e. objects are equal and now its hashCode is asked which is always independent of the fact that whether objects are equal or not. So, GetHashCode for both of the objects returns different value. Ques: 100 The assembly class is defined in?? Ans: The assembly class is defined inSystem.Reflection. Ques: 101 What is the first step to do anything with assembly??

Ques: 102 How do you load assembly to running process ?? Ans: By using Assembly.Load( )and Assembly.LoadFrom( ) we can loadssembly to running process Ques: 103 Assemblies cannot be loaded side by side?? Ans: True.Assemblies cannot be loaded side by side. Ques: 104 Where Application Isolation is assured using ?? Ans: Application Isolation is assured using:- Load assembly to running process Ques: 105 Where does the version dependencies recorded ? Ans: ApplicationDomain Ques: 106 How do you refer parent classes in C# ? Ans: base keyword is used Ques: 107 Which attribute you generally find on top of main method ?? Ans: STAthread stands for Single Thread Application Ques: 108 How do you make a class not instantiable?? Ans: We can make a class not instantiable by making abstract class.

C# Interview Questions And Answers Page 1 Ques: 1 Explain Exception handling Ans: Exception Handling:-# provides built-in support for handling anomalous situations, known as exceptions, which may occur during the execution of your program. These exceptions are handled by code that is outside the normal flow of control. The try, throw, catch, and finally keywords implement exception handling. Throw:-The throw statement is used to signal the occurrence of an anomalous situation (exception) during the program execution. The throw statement takes the form: throw [expression]; where: expression :The exception object. This is omitted when re-throwing the current exception object in a catch clause. Try:The try-block contains the guarded code block that may cause the exception. The block is executed until an exception is thrown or it is completed successfully. For example, the following attempt to cast a null object raises the NullReferenceException exception: object o2 = null; try { int i2 = (int) o2; }

// Error

Catch:The catch clause can be used without arguments, in which case it catches any type of exception, and referred to as the general catch clause. It can also take an object argument derived from System.Exception, in which case it handles a specific exception. For example: catch (InvalidCastException e) { } Finally:finally is used to guarantee a statement block of code executes regardless of how the preceding try block is exited. The finally block is useful for cleaning up any resources allocated in the try block. Control is always passed to the finally block regardless of how the try block exits. The tryfinally statement takes the form: try try-block finally finally-block where: try-block Contains the code segment expected to raise the exception. finally-block Contains the exception handler and the cleanup code. Ques: 2 Explain exception handling in C#? Ques: 3 What is Event? Ans: Event:-The Event model in C# finds its roots in the event programming model that is popular in asynchronous programming. The basic foundation behind this programming model is the idea of "publisher and subscribers." Example:using System; using System.IO; namespace EventExample { public class MyClass { public delegate void LHandler(string message); // Define an Event based on the above Delegate public event LHandler Log; // Instead of having the Process() function take a delegate // as a parameter, we've declared a Log event. Call the Event, public void Process() { OnLog("Process() begin"); OnLog("Process() end"); } protected void OnLog(string message)

{ if (Log != null) { Log(message); } } } // The FLog class merely encapsulates the file I/O public class FLog { FileStream fileStream; StreamWriter streamWriter; // Constructor public FLog(string filename) { fileStream = new FileStream(filename, FileMode.Create); streamWriter = new StreamWriter(fileStream); } // Member Function which is used in the Delegate public void Logger(string s) { streamWriter.WriteLine(s); } public void Close() { streamWriter.Close(); fileStream.Close(); } } public class TestApplication { static void Logger(string s) { Console.WriteLine(s); } static void Main(string[] args) { FLog fl = new FLog("process.log"); MyClass myClass = new MyClass(); // Subscribe the Functions Logger and fl.Logger myClass.Log += new MyClass.LHandler(Logger); myClass.Log += new MyClass.LHandler(fl.Logger); // The Event will now be triggered in the Process() Method myClass.Process();

fl.Close(); } } } Compile an test: # csc EventExample.cs # EventExapmle.exe Process() begin Process() end # cat process.log Process() begin Process() end

An event is a placeholder for code that is executed when the event is triggered, or fired. Events are fired by a user action, program code, or by the system.

The following important conventions are used with events: * Event Handlers in the .NET Framework return void and take two parameters. * The first paramter is the source of the event; that is the publishing object. * The second parameter is an object derived from EventArgs. * Events are properties of the class publishing the event. * The keyword event controls how the event property is accessed by the subscribing classes. Ques: 4 What is indexer? Ans: Indexer:* Indexer Concept is object act as an array. * Indexer an object to be indexed in the same way as an array. * Indexer modifier can be private, public, protected or internal. * The return type can be any valid C# types. * Indexers in C# must have at least one parameter. Else the compiler will generate a compilation error. Signature:his [Parameter] { get

{ // Get codes goes here } set { // Set codes goes here } } ................................................. Exapmle:using System; using System.Collections.Generic; using System.Text;

namespace Indexers { class PClass { private string[] range = new string[5]; public string this[int indexrange] { get { return range[indexrange]; } set {

range[indexrange] = value; } } }

/* The Above Class just act as array declaration using this pointer */

class cclass { public static void Main() { PClass obj = new PClass();

obj[0] = "ONE"; obj[1] = "TWO"; obj[2] = "THREE"; obj[3] = "FOUR "; obj[4] = "FIVE"; Console.WriteLine("WELCOME TO C# CORNER HOME PAGE\n"); Console.WriteLine("\n");

Console.WriteLine("{0}\n,{1}\n,{2}\n,{3}\n,{4}\n", obj[0], obj[1], obj[2], obj[3], obj[4]); Console.WriteLine("\n"); Console.WriteLine("ALS.Senthur Ganesh Ram Kumar\n"); Console.WriteLine("\n"); Console.ReadLine();

} } } Ques: 5 What is Methods? Ans: Method:-Method is object-oriented item of any language. All C# programs are constructed from a number of classes and almost all the classes will contain methods. A class when instantiated is called an object. Object-oriented concepts of programming say that the data members of each object represent its state and methods represent the object behavior. Method Signature:Each method is declared as follows: Access modifier

Return-type methodname ( Parameterslist );

Example:- public string printpro(string s,int y); Ans: Method:-Method is object-oriented item of any language. All C# programs are constructed from a number of classes and almost all the classes will contain methods. A class when instantiated is called an object. Object-oriented concepts of programming say that the data members of each object represent its state and methods represent the object behavior. Method Signature:Each method is declared as follows: Access modifier

Return-type methodname ( Parameterslist );

Example:- public string printpro(string s,int y); Ques: 6 What is Static classes? Ans: Static Class:-These are simply declared using the static modifier. They cannot be derived from or instantiated, and they have no constructors . Their members must all be static. Example:using System; public static class staticexample { public static void Foo() { Console.WriteLine ("Hello"); } } // Uncommenting this creates a compile-time error, // as static classes can't be derived from // public class DerivationAttempt :staticexample{} class Test

{ static void Main() { staticexample.Foo(); } } Ques: 7 What is Aliases? Ans: Aliases:-C# 2.0 introduces the concept of an "alias". This allows you to effectively name an assembly reference when you compile the code, and use that name to disambiguate between names. As well as disambiguating between identical namespace-qualified names, aliases allow you to disambiguate between names which have been declared within an already used namespace and names which belong to the "root" namespace. This is achieved with the predefined alias of global. Example:using System; namespace Foo.Bar { public class Baz { public static void SayHiLib() { Console.WriteLine ("Hello Lib"); } } } Baz.cs: using System; namespace Foo.Bar { public class Baz { public static void SayHiNested() { Console.WriteLine ("Hello Nested"); } } } class Baz { public static void SayHiBaz() { Console.WriteLine ("Hello Baz"); } }

Test.cs: extern alias X; namespace Foo.Bar { class Test { public static void Main() { Baz.SayHiNested(); global::Baz.SayHiBaz(); X::Foo.Bar.Baz.SayHiLib(); } } } Compile: csc /target:library Lib.cs csc /r:X=lib.dll Baz.cs Test.cs Ques: 8 What is Partial types? Ans: Partial Type:-C# 2.0 introduces the concept of a partial type declaration. This is quite simply a single type which spans multiple files, where each file declares the same type using the partial modifier. The files may refer to members declared within one another without problem (just as forward references within C# is already not a problem). Example:1st Part-partial class Test { string name; static void Main() { Test t = new Test("C# 2.0"); t.SayHello(); } } 2ND PART:using System; partial class Test { Test(string name) { this.name = name; }

void SayHello() { Console.WriteLine ("Hi there. My name is {0}.", name); } Compile with: csc Test1.cs Test2.cs Results: Hi there. My name is C# 2.0. Ques: 9 What is Method Overloading ? Ans: Method Overloading:-A method is considered to be an overloaded method, if it has two or more signatures for the same method name. These methods will contain different parameters but the same return types.It become within the class. A simple example for an overloaded methods are: Public void sum(int a, params int[] varParam); Public void sum(int a); Ques: 10 Wat's Property? Ans: PROPERTY:-Properties provide the opportunity to protect a field in a class by reading and writing to it through the property it is a special method that can return a current object?s state or set it. Simple syntax of properties can see in the following example: public int Old { get {return m_old;} set {m_old = value;} } public string Name { get {return m_name;}

Example:public class prop { private int age; public int humanAge { get //get accessor method { return age; }

set //set accessor method { age = value; } } } So when in main program(C#) user wants to use these set and get method to set and get person age. They will use it as Perop boyAge = new Perop(); //create instance of object boyAge. humanAge = 10; // set the age of boy by using setter method of object int bAge = boyAge. humanAge;// get the age of boy by // using getter method of object Console.WriteLine(" Boy age is {0}"+ bAge ); Class Perop is property holder class. In which humanAge is property implementation.

value : In set method value variable is internal c# variable. User no needs to define it explicitly. Ques: 11 Wat's feature of delegate? Ans: Features of delegates: * A delegate represents a class. * A delegate is type-safe. * We can use delegates both for static and instance methods * We can combine multiple delegates into a single delegate. * Delegates are often used in event-based programming, such as publish/subscribe. * We can use delegates in asynchronous-style programming. * We can define delegates inside or outside of classes. Ques: 12 What's Delegate? Ans: Delegate:- delegate is a type-safe object that can point to another method (or possibly multiple methods) in the application, which can be invoked at later time. when you want to create a delegate in C# you make use of delegate keyword. A delegate type maintains three important pices of information : 1. The name of the method on which it make calls. 2. Any argument (if any) of this method. 3. The return value (if any) of this method. signature of delegate:Access modifier delegate returntype delegatename (passing value must be same as a function ); public delegate int DelegateName(int x, int y); Example:-

namespace MyFirstDelegate { public delegate int MyDelegate(int x, int y); public class MyClass { public static int Add(int x, int y) { return x + y; } public static int Mul(int x, int y) { return x * y; } } class Program { static void Main(string[] args) { MyDelegate del1 = new MyDelegate(MyClass.Add); int addResult = del1(5, 5); Console.WriteLine("5 + 5 = {0}\n", addResult); MyDelegate del2 = new MyDelegate(MyClass.Mul); int multiplyResult = del2(5, 5); Console.WriteLine("5 X 5 = {0}", multiplyResult); Console.ReadLine(); } } }

Ques: 13 What's REF Keyword? Ans: REF:-A reference type and sending a parameter by reference are two different things. If you send a reference type to a method (passed by value), then the reference is passed by value. Since you are sending a reference, you can still access the same object outside of the method using another variable set to the same reference. Now, if you pass that reference by ref, you can modify the value of that parameter so that it holds a new reference to a new object. When you pass it by value, you can't do that. Example:Using System; class Color { public Color() { this.red = 255; this.green = 0; this.blue = 125; } protected int red; protected int green; protected int blue; public void Getscol(ref int red, ref int green, ref int blue) { red = this.red; green = this.green; blue = this.blue; } } class RefTest1App { public static void Main() { Color color = new Color(); int red; int green; int blue; color.Getscol(ref red, ref green, ref blue); Console.WriteLine("red = {0}, green = {1}, blue = {2}", red, green, blue); } } Ques: 14 What's OUT Keyword?

Ans: OUT:-out keyword is used for passing a variable for output purpose. It has same concept as ref keyword, but passing a ref parameter needs variable to be initialized while out parameter is passed without initialized. It is useful when we want to return more than one value from the method.

Example of “out keyword”: class Test { public static void Main() { int a; fun(out a); Console.WriteLine("The value of a is " + a); } public static void fun(out int i) { i=4; //must assigned value. } } The program will result : The value of a is 4 Ques: 15 what's Param? Ans: Params:-The params keyword is used to describe methods that can receive any number of parameters of the specified type, and it results in extra allocations and reduced performance but improves the flexibility of the calling patterns. The main use of the params keyword is to give the ability to create functions that take a variable number of arguments. Example:Public int sumnumber(params int[] list) { int sum = 0; foreach (int i in list) sum += i; return sum; } Public static void Main() { int ans1 = sumnumber(1); int ans2 = sumnumber(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); int ans3 = sumnumber(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); int ans4 = sumnumber()

} OUTPUT:1 55 55 0 Ques: 16 Is there an easy way to get help about an object's member Ans: Absolutely. Visual C#'s context-sensitive Help extends to code as well as to visual objects. To get help on a member, write a code statement that includes the member (it doesn't have to be a complete statement), position the cursor within the member text, and press F1. For instance, to get help on the int data type, you could type int, position the cursor within the word int, and press F1. Ques: 17 Is it possible for objects that don't have an interface to support events? Ans: Yes. To use the events of such an object, however, the object variable must be dimensioned a special way or the events aren't available. Ques: 18 Is it possible to create custom events for an object Ans: Yes, you can create custom events for your own objects and you can also create them for existing objects. Creating custom events, Ques: 19 What’s an interface class? Ans: It’s an abstract class with public abstract methods all of which must be implemented in the inherited classes. Ques: 20 Can you override private virtual methods? Ans: No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access. Ques: 21 Can you declare the override method static while the original method is nonstatic? Ans: No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access. Ans: N0, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override. Ques: 22 . What does the keyword virtual mean in the method definition? Ans: The method can be over-ridden. Ques: 23 Describe the accessibility modifier protected internal.?

Ans: It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in). Ques: 24 When you inherit a protected class-level variable, who is it available to? Ans: Classes in the same namespace. Ques: 25 How do you inherit from a class in C#? Ans: Place a colon and then the name of the base class. Ques: 26 What’s the implicit name of the parameter that gets passed into the class’ set method? Ans: Value, and it’s datatype depends on whatever variable we’re changing. Ques: 27 What’s a multicast delegate? Ans: A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called. Ques: 28 What’s a delegate? Ans: Delegate:-A delegate object encapsulates a reference to a method. Ques: 29 What are the different ways a method can be overloaded? Ans: Different parameter data types, different number of parameters, different order of parameters. Ques: 30 Can you declare an override method to be static if the original method is not static? Ans: No. The signature of the virtual method must remain the same. (Note: Only the keyword virtual is changed to keyword override) Ques: 31 What does the keyword “virtual” declare for a method or property? Ans: The method or property can be overridden. Ques: 32 What’s the implicit name of the parameter that gets passed into the set method/property of a class? Ans: Value. The data type of the value parameter is defined by whatever data type the property is declared . Ques: 33 What is the difference between a Struct and a Class? Ans: Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that structs cannot inherit. Ques: 34 What’s the difference between an interface and abstract class? Ans: n an interface class, all methods are abstract - there is no implementation. In an abstract

class some methods can be concrete. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers. Ques: 35 What happens if you inherit multiple interfaces and they have conflicting method names? Ans: It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay. Ques: 36 What is an interface class? Ans: Interface:-Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes. Ques: 37 .When do you absolutely have to declare a class as abstract? Ans: 1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden. 2. When at least one of the methods in the class is abstract. Ques: 38 .What’s an abstract class? Ans: Abstract Class:-A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation. Ques: 39 Can you allow a class to be inherited, but prevent the method from being overridden? Ans: Just leave the class public and make the method sealed. Ques: 40 Explain the three services model commonly know as a three-tier application? Ans: these are:-Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources). Ques: 41 .What class is underneath the SortedList class? Ans: sorted HashTable. Ques: 42 What’s the .NET collection class that allows an element to be accessed using a unique key? Ans: Hash Table Ques: 43 Can you store multiple data types in System.Array? Ans: no,we cant store multiple data types in System.Array? Ques: 44

What does the term immutable mean? Ans: Immutable means the data value may not be changed. Ques: 45 Describe the accessibility modifier “protected internal”. Ans: It is available to classes that are within the same assembly and derived from the specified base class. Ques: 46 How can I create a process that is running a supplied native executable (e.g., cmd.exe)? Ans: The following code should run the executable and wait for it to exit before continuing: using System; using System.Diagnostics; public class ProcessTest { public static void Main(string[] args) { Process p = Process.Start(args[0]); p.WaitForExit(); Console.WriteLine(args[0] + " exited."); } } Remember to add a reference to System.Diagnostics.dll when you compile. Ques: 47 Can you inherit multiple interfaces? Ans: Yes. .NET does support multiple interfaces. Ques: 48 Are private class-level variables inherited? Ans: Yes, but they are not accessible. Ques: 49 Can you change the value of a variable while debugging a C# application? Ans: Yes, if you are debugging via Visual Studio.NET, just go to Immediate window. Ques: 50 Can you allow class to be inherited, but prevent the method from being overridden? Ans: Yes, just leave the class public and make the method sealed Ques: 51 What is the top .NET class that everything is derived from? Ans: System,Object Ques: 52 What does the parameter Initial Catalog define inside Connection String? Ans: The database name to connect to. Ques: 53 What is the difference between const and static read-only? Ans: The difference is that static read-only can be modified by the containing class, but const can never be modified and must be initialized to a compile time constant. To expand on the

static read-only case a bit, the containing class can only modify it: -- in the variable declaration (through a variable initializer). -- in the static constructor (instance constructors if it's not static). Ques: 54 What is the equivalent to regsvr32 and regsvr32 /u a file in .NET development? Ans: using RegAsm.exe. The general syntax would be: RegAsm. A good description of RegAsm and its associated switches is located in the .NET SDK docs. Just search on "Assembly Registration Tool".Explain ACID rule of thumb for transactions. Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no in-between case where something has been updated and something hasnot), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after). Ques: 55 Why do I get a syntax error when trying to declare a variable called checked? Ans: The word checked is a keyword in C#. Ques: 56 Why cannot you specify the accessibility modifier for methods inside the interface? Ans: Because They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it is public by default. Ques: 57 C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write? Ans: Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there is no implementation in Ques: 58 How do I create a multi language, multi file assembly? Ans: Unfortunately, this is currently not supported in the IDE. To do this from the command line, you must compile your projects into netmodules (/target:module on the C# compiler), and then use the command line tool al.exe (alink) to link these netmodules together. Ques: 59 How do I register my code for use by classic COM clients? Ans: Use the regasm.exe utility to generate a type library (if needed) and the necessary entries in the Windows Registry to make a class available to classic COM clients. Once a class is registered in the Windows Registry with regasm.exe, a COM client can use the class as though it were a COM class. Ques: 60 What is the implicit name of the parameter that gets passed into the class set method? Ans: The implicit name of he parameter that gets passed into the class set method is Value, and its datatype depends on whatever variable we are changing. Ques: 61 When do you absolutely have to declare a class as abstract?

Ans: absolutely have to declare a class as abstract :When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden. Ques: 62 When do you absolutely have to declare a class as abstract Ans: We do absolutely have to declare a class as abstract When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden. Ques: 63 How is method overriding different from overloading? Ans: When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class. Ques: 64 What is a satellite assembly? Ans: satellite assembly:-When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies. Ques: 65 Is there a way to force garbage collection? Ans: yes,Yes. Set all references to null and then call System.GC.Collect(). If you need to have some objects destructed, and System.GC.Collect() doesn't seem to be doing it for you, you can force finalizers to be run by setting all the references to the object to null and then calling System.GC.RunFinalizers(). Ques: 66 Is there regular expression (regex) support available to C# developers? Ans: Yes. The .NET class libraries provide support for regular expressions. Look at the documentation for the System.Text.RegularExpressions namespace. Ques: 67 Will finally block get executed if the exception had not occurred? Ans: yes,finally block will get executed if the exception had not occurred Ques: 68 Can you prevent your class from being inherited and becoming a base class for some other classes? Ans: Yes,we can prevent class from being inherited by using sealed class, keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class Whatever BaseClassName. It is the same concept as final class in Java. Ques: 69 What is delay signing? Ans: Delay signing:-It allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development.

Ques: 70 How do I make a DLL in C#? Ans: To make a Dll in C# we need to use the /target:library compiler option. Ques: 71 How do I simulate optional parameters to COM calls? Ans: You must use the Missing class and pass Missing.Value (in System.Reflection) for any values that have optional parameters. Ques: 72 Can you have two files with the same file name in GAC? Ans: Yes, remember that GAC is a very special folder, and while normally you would not be able to place two files with the same name into a Windows folder, GAC differentiates by version number as well, so it’s possible for MyApp.dll and MyApp.dll to co-exist in GAC if the first one is version 1.0.0.0 and the second one is 1.1.0.0. Ques: 73 Where’s global assembly cache located on the system? Ans: global assembly cache located on the system in C:\winnt\assembly or C:\windows\assembly. Ques: 74 How can you create a strong name for a .NET assembly? Ans: To create a strong name for a .NET assembly With the help of Strong Name tool (sn.exe). Ques: 75 Where are shared assemblies stored? Ans: shared assemblies stored in Global assembly cache. Ques: 76 What’s a strong name? Ans: Strong Name:-A strong name includes the name of the assembly, version number, culture identity, and a public key token. Ques: 77 What’s the difference between private and shared assembly? Ans: Private assembly is used inside an application only and does not have to be identified by a strong name. Shared assembly can be used by multiple applications and has to have a strong name. Ques: 78 What do you know about .NET assemblies? Ans: Assemblies are the smallest units of versioning and deployment in the .NET application. Assemblies are also the building blocks for programs such as Web services, Windows services, serviced components, and .NET remoting applications. Ques: 79 What's C# ? Ans: C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection. Ques: 80

Is it possible to have different access modifiers on the get/set methods of a property? Ans: No. The access modifier on a property applies to both its get and set accessors. What you need to do if you want them to be different is make the property read-only (by only providing a get accessor) and create a private/internal set method that is separate from the property. Ques: 81 Can multiple catch blocks be executed? Ans: No, multiple catch blocks can not be executed. once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block. Ques: 82 Why are there five tracing levels in System.Diagnostics.TraceSwitcher? Ans: The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities. Ques: 83 What’s the difference between the Debug class and Trace class? Documentation looks the same Ans: Debug class is Used for debug builds,and Trace class used for both debug and release builds. Ques: 84 How do you generate documentation from the C# file commented properly with a command-line compiler? Ans: For generate documentation from the C# file commented properly with a command-line compile:- Compile it with a /doc switch. Ans: To generate documentation from the C# file commented properly with a command-line compiler- Compile it with a /doc switch. Ques: 85 What’s the difference between // comments, /* */ comments and /// comments Ans: // comments means Single-line comments , /* */ comments means multi-line and /// comments means XML documentation comments. Ques: 86 What namespaces are necessary to create a localized application? Ans: The Namespace are necessary to create a localized application is System.Globalization, System.Resources. Ques: 87 What’s a satellite assembly? Ans: Satellite Assembly:-When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies. Ques: 88 Question:-How’s the DLL Hell problem solved in .NET?

Ans: Since Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly. Ques: 89 Question:-What’s a multicast delegate? Ans: Multicast delegate is a delegate that points to and eventually fires off several methods. Ques: 90 Question:-What’s a delegate? Ans: A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers. Ques: 91 Question:-Can multiple catch blocks be executed? Ans: No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block. Ques: 92 Question:-How can you sort the elements of the array in descending order? Ans: we can sort the elements of the array in descending order By calling Sort() and then Reverse() methods. Ans: we can sort the elements of the array in descending order By calling Sort() and then Reverse() methods. Ques: 93 Question:-What’s the difference between the System.Array.CopyTo() and System.Array.Clone()? Ans: System.Array.CopyTo() performs a deep copy of the array, the System.Array.Clone is shallow. Ques: 94 What’s the advantage of using System.Text.StringBuilder over ? Ans: StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created. Ques: 95 QUESTION:-What’s the advantage of using System.Text.StringBuilder over Ques: 96 explain static equal()method? Ques: 97 Write one code example for compile time binding and one for run time binding. Ans: class Ans: Ans: polymorphism Ques: 98 What happens when you encounter a continue statement inside for loop? Ans: loop will execute Ans: means to continue executing next line

Ans: It continues from the loop start again keeping same counter. Ques: 99 IS goto statement supported in C#?How about Java? Ans: C# will support.. Java won't support Ans: NO Ans: Goto is supported in C# although not recommended. Not supported in java. Ques: 100 What optimization does the C# compiler perform when you use the optimize & compiler option?

Page 6 Ques: 101 Is there an equivalent of exit() or quiting a C#.NET application? Ans: yes Ans: environment.exit() Ans: Return Ans: this.Dispose(); Ans: Break; Ans: Application.Exit(); Or System.Environment.Exit(); Ques: 102 IS it possible to have different access modifiers on the get/set methods of a property? Ques: 103 Does C# has its own class library? Ans: Yes Ans: yes Ques: 106 Where we can use DLL made in C#.Net? Ans: Namespace Ques: 116 Can I call a virtual method from a constructor/destructor? Ans: No

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF