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.
Delegates have the following properties:
· Also know as custom events.
· Delegates allow methods to be passed as parameters.
· Delegates can be used to define callback methods.
· Delegates can be chained together; for example, multiple methods can be called on a single event.
Example:
public delegate void SimpleDelegate();
public delegate void ButtonClickHandler(int obj1, int obj2);
class Program
{
static void Main(string[] args)
{
A a = new A();
SimpleDelegate sd = new SimpleDelegate(a.Sum);
ButtonClickHandler handler = new ButtonClickHandler(a.Sum);
}
}
public class A
{
public A() { }
int i;
float f;
public void Sum() { }
public void Sum(int x,int y){}
}
Delegates & Events very well explained at:
Nice explanation about Events in C# --
2. What is the use of private constructor - It will not allow the instantiation of the object (new)
A private constructor is a special instance constructor.
It is commonly used in classes that contain static members only.
If a class has one or more private constructors and no public constructors, then other classes (except nested classes) are not allowed to create instances of this class.
The declaration of the empty constructor prevents the automatic generation of a default constructor.
Note that if you don't use an access modifier with the constructor it will still be private by default.
However, the private modifier is usually used explicitly to make it clear that the class cannot be instantiated.
Private constructors are useful to prevent creation of a class when there are no instance fields or methods, such as the Math class
3. What is Aggregation and Composition
4. How is caching done
Cache Application Programming Interfaces (APIs) allow you to programmatically store arbitrary objects to memory
so that your application can save the time and resources that it takes to re-create them.
Cache APIs allow you to expire items from the cache based on the following credentials:
· Time
· File dependencies
· Cache key dependencies
ASP.NET has a powerful, easy-to-use caching mechanism that allows you to store objects that require a
large amount of server resources to create in memory.
It is implemented by the Cache
with instances private to each application, and its lifetime is tied to that of the application.
When the application is restarted, the Cache object is recreated.
The Cache class has been designed for ease of use.
By using keys paired with values, you can place items in the Cache and later retrieve them.
While the Cache class offers a simple interface for you to customize cache settings,
it also offers powerful features that allow you to customize how items are cached and how long they are cached.
For example, when system memory becomes scarce, the cache automatically removes seldom used or unimportant items to
allow memory to be used to process a high volume of requests. This technique is called scavenging.
Scavenging is one of the ways that the cache ensures that data that is not current does not consume valuable
server resources.
You can instruct the Cache to give certain items priority over other items when it performs scavenging.
To indicate that a specific item is of greater or lesser importance than another, specify one of the
CacheItemPriority
enumeration values when you add an item using the Cache.Add
You can also establish an expiration policy for an item when you add it to the Cache using the Add method or Insert method.
You can define the lifetime for an item by using the absoluteExpiration parameter, which is of the type DateTime
item will expire. You can also use the slidingExpiration parameter, which is of the type TimeSpan
It allows you to specify the elapsed time
before the item expires based on the time it is accessed. Once the item expires, it is removed from the cache.
Attempts to retrieve its value will return null unless the item is added to the Cache again.
For volatile items that are stored in the Cache, such as those that have regular data refreshes,
or those that are valid for only a set amount of time, set an expiration policy that keeps those
items in the Cache as long as their data remains current. For example, if you are writing an application
that tracks sports scores by obtaining the data from a frequently updated Web site, you can cache the scores
for a game as long as those scores do not change on the source Web site. In this case, you can set an expiration
policy that is based on how often the Web site updates the scores.
You can write code that determines if an up-to-date score is in the Cache. If the score is not up to date,
the code can update the score from the source Web site.
Finally, ASP.NET allows you to define the validity of a cached item, based on an external file, a directory,
or another cached item. These are called file dependencies and key dependencies.
If a dependency changes, the cached item is invalidated and removed from the Cache.
You can use this technique to remove items from the Cache when their data source changes.
For example, if you write an application that processes financial data from an XML file
and renders it in a graph, you can insert the data from the file in the Cache and maintain
a dependency on that XML file. When the file is updated, the item is removed from the cache,
your application rereads the file, and a new version of the item is inserted.
Note The Cache has no information about the content of the items it contains.
It merely holds a reference to those objects. It also provides methods to track their
dependencies and set expiration policies.
5. What is the purpose of global.asax file
The Global.asax file (also known as the ASP.NET application file) is an optional file that is located in the
application's root directory and is the ASP.NET counterpart of the Global.asa of ASP.
This file exposes the application and session level events in ASP.NET and provides a gateway to
all the application and the session level events in ASP.NET.
This file can be used to implement the important application and session level events such as
Application_Start, Application_End, Session_Start, Session_End, etc.
This article provides an overview of the Global.asax file, the events stored in this file and how
we can perform application wide tasks with the help of this file.
è For in-depth reading
Global.asax is an optional file used to declare and handle application- and session-level events and objects
The Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for
responding to application-level events raised by ASP.NET or by HttpModules.
The Global.asax file resides in the root directory of an ASP.NET-based application.
At run time, Global.asax is parsed and compiled into a dynamically generated .NET Framework class derived
from the HttpApplication
The Global.asax file itself is configured so that any direct URL request for it is automatically rejected;
external users cannot download or view the code written within it.
The Global.asax file is optional.
If you do not define the file, the ASP.NET page framework assumes that you have
not defined any application or session event handlers.
When you save changes to an active Global.asax file, the ASP.NET page framework detects that the file
has been changed. It completes all current requests for the application, sends the Application_OnEnd
listeners, and restarts the application domain.
In effect, this reboots the application, closing all browser sessions and flushing all state information.
When the next incoming request from a browser arrives, the ASP.NET page framework reparses and recompiles
the Global.asax file and raises the Application_OnStart
6. What are the # of pages/forms you have developed in your career (strange question)
7. What is the purpose of sealed keyword
A sealed class cannot be used as a base class. For this reason, it cannot also be an abstract class.
Sealed classes are primarily used to prevent derivation.
Because they can never be used as a base class, some run-time optimizations can make calling sealed class
members slightly faster.
Sealing a class means one cannot derive from it.
Sealing a method means one cannot override it.
In C# structs are implicitly sealed; therefore, they cannot be inherited.
If we try to inherit from a sealed class in another class we will get compile time error about Inconsistent accessibility
public sealed class cSealed
{
// Class members here.
public string ID;
public double Price;
}
The most likely situation in which we make a class or method sealed will be if the class or method is internal to the operation of the library, class, or other classes that we are writing. Because any attempt to override some of its functionality will cause problems. We can mark a class or method as sealed for commercial reasons, in order to prevent a third party from extending our classes. For example, in the .NET base class library string is a sealed class.
We should not use the sealed key word on a method unless that method is itself an override of another method in some base class. If we are defining a new method and we don’t want anyone else to override it, we should not declare it as virtual in the first place. If however, we have overridden a base class method, the sealed keyword provides a way of ensuring that the override supplied to a method is a “final” override that means no one else can override it again.
8. Have you used application blocks? What is the application blocks used.
With a view to promote enterprise development, enhance developer productivity, reduce development time, facilitate efficient code maintenance and rapid application development
è Simplicity and ease of use
è Extensibility as the source code for each of these blocks are available for free
è Integration with other blocks
è Consistency
9. What are web services
Web Services
Synchronous & Asynchronous communication
Web Services
Common Terminology used in Web Services
SOAP Simple Object Access Protocol (SOAP) is a way to structure data so that any computer program in any language can read SOAP and send messages in SOAP. This is because it is XML based and language and platform independent. SOAP supports any transport protocol and use Hyper Text Transfer Protocol (HTTP), File Transfer Protocol (FTP), Simple Mail Transfer Protocol (SMTP) and Post Office Protocol 3 (POP3) to carry documents.
Web Services Description Language (WSDL)
Web Services
Universal Description, Discovery, and Integration (UDDI)
Universal Description, Discovery, and Integration (UDDI) is an open, Internet-based specification that is the building block on which businesses may quickly and easily locate desired services and perform business with one another.
DISCO
Abbreviation of DISCO is Discovery.It is basically used to club or group common services together on a server and provide links to the schema documents of the services it describes may require.
Transport Protocol for Web Service
Unless we specify otherwise, .NET will attempt to bind Web Services to three separate protocols: HTTP/POST, HTTP/GET, and SOAP. Bindings for these three protocols will be included in the WSDL file automatically generated by .NET and consumer clients will have the option of choosing any one of them for communication with service. However, GET and POST are limited to sending and receiving name/value pairs of data whereas we can use SOAP to serialize complex structure, such as ASP.NET DataSets, complex arrays, custom types and XML nodes.
We can easily remove these bindings by adding the followings as specified in Listing 1 to our web.config file as:
Listing 1
This section will tell the WSDL generator not to include bindings for HTTP/POST and HTTP/GET. The two remove sections specify that HttpPost and HttpGet should not be supported. With regard to interoperability where SOAP is a widely-used standard for Web Service communication, HTTP/GET and HTTP/POST are not. As a result, many automatic proxy generation tools were not designed to understand the HTTP/GET and HTTP/POST bindings included by default in a .NET-generated WSDL document. If our service does not make use of these bindings, removing them can increase our service's interoperability.
The Web Service Attribute
The Web Service Attribute is a member of the System.Web.Services namespace. This we can use to let the clients know where to find information about a Web Service. There are three properties of the Web Service attribute. They are as follows: 1. Description 2. Namespace 3. Name Description The Description property is used to provide a brief description of the functionality of the class. We can write the same as specified in Listing 2. Listing 2 [WebService(Description="This class contains methods for working with Addition of numbers and Population of DataSet")] Namespace The Namespace property sets the XML namespace for the service. Generally we use an URL. It does not have to be an actual URL; it can be any string value. The idea is that it should be unique. It is common practice to use URL because a URL is always unique. Name When the WSDL is generated for an ASP.NET Web Service, the name of the class is used for the service name within the WSDL. When a proxy uses the WSDL and builds a proxy class, the name of the class generated corresponds to the name value of service. This property allows overriding the default value.
Extension - .asmx
In .NET’s Remoting technology we require the Server and the Client both to be of the same technology; in other words, they should both be .NET applications and require the .NET framework to be running in both of these environments. This is in contrast to Web Services where a typical Web Service implemented in .NET can even be invoked for Java.
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// Description ………………
// [System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service () { InitializeComponent(); }
[WebMethod]
public string Add(int a, int b)
{
return Convert.ToString(a + b);
}
[WebMethod]
public DataSet Populate(string con, string sql)
{
DataSet DS = new DataSet();
SqlConnection conn = new SqlConnection(con);
SqlDataAdapter DA = new SqlDataAdapter(sql, conn);
DA.Fill(DS);
return DS;
}
}
10. What is the difference between String and String Builder
The String object is immutable. Every time you use one of the methods in the System.String class, you create a new string object in memory, which requires a new allocation of space for that new object. In situations where you need to perform repeated modifications to a string, the overhead associated with creating a new String object can be costly. The System.Text.StringBuilder
StringBuilder myStringBuilder = new StringBuilder ( "Hello World!" );
11. What will happen if a class is implementing multiple interfaces which have same methods?
It’s up to you on how you implement the method inside your own class. It may cause problems on higher scale, if similarly named methods from different interfaces expect different data, but as far as compiler is concerned, it’s okay.
12. What is an abstract class?
An abstract class only allows other classes to inherit from it and cannot be instantiated. When we create an abstract class, it should have one or more completed methods but at least one or more uncompleted methods and these must be preceded by the key word abstract. If all the methods of an abstract class are uncompleted then it is the same as an interface, but there is a restriction that it cannot make a class inherit from it, which means it cannot work as a base class.
13. What is an interface?
An interface is defined by the key word interface. An interface has no implementation; it only has the definition of the methods without the body. When we create an interface, we are basically creating a set of methods without any implementation. A class implementing an interface must provide the implementation of the interface members. All the methods and properties defined in an interface are by default public and abstract.
14. Explain when to choose one over the other (interface and abstract class).
è Abstract classes can add more functionality without destroying the child classes that were using the old version. Abstract classes provide a simple and easy way to version our components. By updating the base class, all inheriting classes are automatically updated with the change. In an interface, creation of additional functions will have an effect on its child classes due to the necessary implementation of interface Methods in classes.
è Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes. Say there are two classes, bird and airplane, and both of them have methods called fly. It would be ridiculous for an airplane to inherit from the bird class just because it has the fly() method. Rather, the fly() method should be defined as an interface and both bird and airplane should implement that interface. If we want to provide common, implemented functionality among all implementations of component, we should use an abstract class.
è Abstract classes allow us to partially implement classes, whereas interfaces contain no implementation for any members. So the selection of interface or abstract classes depends on the needs and design of our project. We can make an abstract class, interface, or combination of both depending on our needs.
15. Explain briefly Garbage collection in .Net?
Garbage Collection is a technique introduced in Microsoft .NET that manages memory automatically and to free unused objects that go out of the scope automatically.
A "garbage" object is one that is no longer needed, is unreachable from the root or goes out of the scope in which it is created. Microsoft .NET uses the information in the metadata to trace the object graph and detect the objects that need to be garbage collected. Objects that are not reachable from the root are referred to as garbage objects and are marked for garbage collection. It is to be noted here that there is a time gap between the time when an object is identified as garbage and the time when the object is actually collected. It is also to be noted that objects in the managed heap are stored in sequential memory locations. This is unlike C and C++ and makes allocation and de-allocation of objects faster.
Strong and Weak References
The garbage collector can reclaim only objects that have no references. An object that is reachable cannot be garbage collected by the garbage collector. Such a reference is known as a strong reference.
An object can also be referred to as a weak reference; another term for a weak reference is the target. An object is eligible for garbage collection if it does not contain any strong references, irrespective of the number of weak references it contains. Weak references are of the following types:
è Short Weak Reference
è Long Weak Reference
A short weak reference does not track resurrection while a long weak reference tracks resurrection. The primary advantage of maintaining weak references to an object is that it allows the garbage collector to collect or reclaim memory of the object if it runs out of memory in the managed heap.
16. Can you explicitly call garbage collection?
Yes - by using the System.GC class
The System.GC class represents the garbage collector and contains many of methods and properties that are described in this section.
GC.Collect Method
This method is used to force a garbage collection of all the generations. It can also force a garbage collection of a particular generation passed to it as a parameter. The signatures of the overloaded Collect methods are:
public static void Collect();
public static void Collect(Integer int);
Generations
A generational garbage collector collects the short-lived objects more frequently than the longer lived ones. Short-lived objects are stored in the first generation, generation 0. The longer-lived objects are pushed into the higher generations, 1 or 2. The garbage collector works more frequently in the lower generations than in the higher ones.
When an object is first created, it is put into generation 0. When the generation 0 is filled up, the garbage collector is invoked. The objects that survive the garbage collection in the first generation are promoted onto the next higher generation, generation 1. The objects that survive garbage collection in generation 1 are promoted onto the next and the highest generation, generation 2. This algorithm works efficiently for garbage collection of objects, as it is fast. Note that generation 2 is the highest generation that is supported by the garbage collector.
Garbage Collection is one of the most striking features introduced in Microsoft .NET. It is however, not advisable to implement the finalize method unless it is mandatory. An object that has the finalize method implemented has to undergo two generations before it gets garbage collected from the managed heap. Hence, it slows down the operations.
17. What is the difference between public, internal and protected modifiers?
Access modifiers are keywords used to specify the declared accessibility of a member or a type. This section introduces the four access modifiers:
· public
· protected
· internal
· private
The following five accessibility levels can be specified using the access modifiers:
public protected internal internal protected private
public - The public keyword is an access modifier for types and type members. Public access is the most permissive access level. There are no restrictions on accessing public members.
The protected keyword is a member access modifier. A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declared this member.
A protected member of a base class is accessible in a derived class only if the access takes place through the derived class type.
The internal keyword is an access modifier for types and type members. Internal members are accessible only within files in the same assembly. For more information on assemblies, see Components and Assemblies
A common use of internal access is in component-based development because it enables a group of components to cooperate in a private manner without being exposed to the rest of the application code. For example, a framework for building graphical user interfaces could provide Control and Form classes that cooperate using members with internal access. Since these members are internal, they are not exposed to code that is using the framework.
It is an error to reference a member with internal access outside the assembly within which it was defined.
Caution An internal virtual method can be overridden in some languages, such as textual Microsoft intermediate language (MSIL) using Ilasm.exe, even though it cannot be overridden using C#.
The private keyword is a member access modifier. Private access is the least permissive access level. Private members are accessible only within the body of the class or the struct in which they are declared.
Nested types in the same body can also access those private members.
It is a compile-time error to reference a private member outside the class or the struct in which it is declared.
Declared accessibility Meaning
public Access is not restricted.
protected Access is limited to the containing class or types derived from the containing class.
internal Access is limited to the current assembly.
protected internal Access is limited to the current assembly or types derived from the containing class.
private Access is limited to the containing type.
Only one access modifier is allowed for a member or type, except for the protected internal combination.
18. What are value and reference types?
Value types directly contain their data are either allocated on the stack or allocated in-line in a structure. Reference types store a reference to the value's memory address, and are allocated on the heap. Reference types can be self-describing types, pointer types, or interface types. Variables that are value types each have their own copy of the data, and therefore operations on one variable do not affect other variables. Variables that are reference types can refer to the same object; therefore, operations on one variable can affect the same object referred to by another variable. All types derive from the System.Object base type.
19. What is boxing/unboxing?
Boxing permits any value type to be implicitly converted to type object or to any interface type implemented by value type.Boxing is process in which a object instances created and copying value types value in to that instance. Unboxing is vice versa of boxing operation where the value is copied from the instance in to appropriate storage location. Below is sample code of boxing and unboxing where integer data type is converted in to object and then vice versa.
Dim x As Integer
Dim y As
Object x = 10
‘ boxing process
y = x
‘ unboxing process
x = y
20. State the advantages n disadvantages of Array & ArrayList
ArrayList - Implements the IList interface using an array whose size is dynamically increased as required.
ArrayList is: a datatype collection. In order to fill an ArrayList, one can use the .Add property. ArrayLists are very dynamic in the sense that when you add and/or remove items from it, the performace stays the same.
The internal structure of an ArrayList is an array.
Examples:
o ArrayList myArray = new ArrayList();
o myArray .Add(“Steph”);
o string str = myArray [0];
Array is: a datatype, thatcan be used by calling indexes. during runtime, one cannot really change the size of the array, unless you use the method of copying the array and getting rid of the old one.
In .NET, the Visual Studio makes use of a special class to store the data. Because of this, the performance is actually quite fast. This is also because in an array, you need to specify the size and thus, the data is stored one after the other.
Examples:
o int[ ] myNumbers= new int[5];
o myNumbers[0] = 16;
Most of the time, we tend to choose array lists rather than arrays since we have no idea how big it is going to turn out. Arrays are ideal when you know how many items you are going to put in it. Whenever possible, it is recommended to use arrays as this drastically improves the performance.
21. Do we need to manually deallocate memory in .Net (Garbage Collection) (GC.Collect(), GC.SuppressFinalize())
There are two types of allocation used - Managed and unmanaged memory.
If the application is using Managed memory, then there is no need to manually de-allocate the memory, but if its using unmanaged memory allocation (for ex. Files, stream etc.) Then we should manually de-allocate the memory
22. Namespace used by generics? About Generics . . .
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
A a = new A();
B b = (B)a;
GenericsDemo
int x = gd.sum(5,6);
SimpleDelegate sd = new SimpleDelegate(a.Sum);
ButtonClickHandler handler = new ButtonClickHandler(a.Sum);
}
}
public class GenericsDemo
{
T i;
T f;
public T sum
{
return t1;
}
}
Very well explained in msdn:
http://msdn.microsoft.com/en-us/library/ms379564.aspx#csharp_generics_topic4
Generics are a new concept that has been introduced with C# 2.0 and it helps us to defer the binding of a generic type to a data type until its point of usage arrives. It is one of the most powerful and anticipated feature of the C# 2.0 language. The basic idea behind generics is to develop universal classes and methods that can accept a type as a parameter to promote reusability, efficiency and maintainability of code.
Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code.
Generics facilitate type safety, improved performance and reduced code. It promotes the usage of parameterized types on our types and is also known as parametric polymorphism. The Common Language Runtime (CLR) compiles any Generic type to IL and Metadata as it does with the other types; but it stores added information pertaining to the generic types which is used to bind the generic type to a specific type at runtime when the generic type is instantiated. Note that for generic types that are bound to value types, the generic types are instantiated for each value type that it is bound to. Unlike this, for generic types that are bond to reference types, the generic type instance refers to the location in memory of the reference type to which it is bound for all the instances of the generic type.
23. Does C# support multi level inheritance? ---- Yes
24. What happens if a class has private constructor?
A private constructor is one that prevents the creation of the object of the class. It is commonly used in classes that contain only static members.
A constructor is a member function that has the same name as the class name and is invoked automatically when the class is instantiated. A constructor is used to provide initialization code that gets executed every time the class is instantiated.
Points to be noted on constructors:
· Constructors cannot be "virtual".
· They cannot be inherited.
· Constructors are called in the order of inheritance.
· If we don't write any constructor for a class, C# provides an implicit default constructor, i.e., a constructor with no argument.
· Constructors cannot return any value.
· Constructors can be overloaded.
C# supports two types of constructor, a class constructor (static constructor) and an instance constructor (non-static constructor).
Static constructor is used to initialize static data members as soon as the class is referenced first time, whereas an instance constructor is used to create an instance of that class with
Since static constructor is a class constructor, they are guaranteed to be called as soon as we refer to that class or by creating an instance of that class.
Non-static constructors can be public, private, protected, external, or internal. A public constructor is one that is called when the class is instantiated. A private constructor is one that prevents the creation of the object of the class. It is commonly used in classes that contain only static members. A class containing an internal constructor cannot be instantiated outside of the assembly. An internal constructor can be used to limit concrete implementations of the abstract class to the assembly defining the class. A protected constructor allows the base class to do its own initialization when subtypes are created. When constructor declaration includes an extern modifier, the constructor is said to be an external constructor. An external constructor declaration provides no actual implementation and hence does not contain any definition. It is to be noted that a public constructor can access a private constructor of the same class through constructor chaining.
27. What is encapsulation? In a class, we have a variable called varIlist, and some method is returning this variable, do you think is it breaking the Encapsulation?
Encapsulation is a property of OOPS that combines the data and the members of a class inside a unit resulting in an isolation of the unit from the external world. It exposes only the functional details, but hides the implementation details of the class.
The benefits of encapsulation:
· Modularity
· Information-hiding
28. What is interface inheritance?
Inheritance is a feature by virtue of which a child class inherits its parent. A subclass inherits all the members of its base, except those that are private. A sub class may have one or more base classes, i.e. it can be inherited from one or more bases. Such type of inheritance is known as Multiple Inheritance. A sub class can also extend the behavior of its inherited members and add new members. Here it needs to be mentioned that there are two relationships in OOPS- "has-a" and "is-a." The former indicates a composition, while the later indicates inheritance. Inheritance offers the following benefits:
· Reusability
· Implement Abstract Data Types
Multiple inheritances are possible for Interface Inheritance
29. What is overriding and overloading?
Overloading occurs when a method has more than one definition in the same scope. It's important to remember two key points from the previous statement: same name and same scope. The method implementations have the same name because they do similar tasks. For instance, if we need to implement a method that gets the student name, there are many ways to do that. We can get the name using an id and we can get the name using a social security number. One way to implement the methods is as follows:
class Student
{ ...
public string GetName( int id) {...}
public string GetName( string ssn) {...}
...
}
The method GetName() is overloaded since the two implementations are in the same scope (class scope) and have the same name. If the methods are declared in different scopes (for example, different classes), then we are not talking about overloading.
Overriding has to do with parent and child classes. If you are not satisfied with the implementation of a method in the parent class, you can keep the same declaration (signature and return type), but provide a different implementation. For example, a Rectangle class inherits the drawing functionality from a Shape class, but it overrides this functionality in order to be able to draw a rectangle.
30. What is the use of private constructors and static constructors? Ref to Q. 24
31. Can protected /sealed be used in interface? - NO. It is public by default and can’t be changed
32. What are destructors?
Destructors are used to destruct instances of classes.
· Destructors cannot be defined in structs. They are only used with classes.
· A class can only have one destructor.
· Destructors cannot be inherited or overloaded.
· Destructors cannot be called. They are invoked automatically.
· A destructor does not take modifiers or have parameters
class Car
{
~ Car() // destructor
{
// cleanup statements...
}
}
33. There is one class A with its constructor and class B with its constructor. Class B inherits Class A. Does constructor of Class A get called? --- Yes
34. What is difference between Response.Redirect and Server.Transfer?
Response.Redirect - Causes the browser to redirect the client to a different URL
Server.Transfer - Sends all of the information that has been assembled for processing by one .asp file to a second .asp file.
35. What is view state?
View state's purpose in life is simple: it's there to persist state across postbacks. (For an ASP.NET Web page, its state is the property values of the controls that make up its control hierarchy.) This begs the question, "What sort of state needs to be persisted?" To answer that question, let's start by looking at what state doesn't need to be persisted across postbacks. Recall that in the instantiation stage of the page life cycle, the control hierarchy is created and those properties that are specified in the declarative syntax are assigned. Since these declarative properties are automatically reassigned on each postback when the control hierarchy is constructed, there's no need to store these property values in the view state.
For example, imagine we have a Label Web control in the HTML portion with the following declarative syntax:
When the control hierarchy is built in the instantiation stage, the Label's Text property will be set to "Hello, World!" and its Font property will have its Name property set to Verdana. Since these properties will be set each and every page visit during the instantiation stage, there's no need to persist this information in the view state.
What needs to be stored in the view state is any programmatic changes to the page's state. For example, suppose that in addition to this Label Web control, the page also contained two Button Web controls, a Change Message Button and an Empty Postback button. The Change Message Button has a Click event handler that assigns the Label's Text property to "Goodbye, Everyone!"; the Empty Postback Button just causes a postback, but doesn't execute any code. The change to the Label's Text property in the Change Message Button would need to be saved in the view state. To see how and when this change would be made, let's walk through a quick example. Assuming that the HTML portion of the page contains the following markup:
And the code-behind class contains the following event handler for the Button's Click event:
private void btnSubmit_Click(object sender, EventArgs e)
{
lblMessage.Text = "Goodbye, Everyone!";
}
36. Which one do you prefer client-side validation, server-side validation?
Client-side validation
37. If JavaScript is disabled from browser then how will client side validation fire?
38. What is association, aggregation and composition
39. Can we access private property in derived classes? - No
40. What is polymorphism? Poly - different forms (Overloading & Overriding )
41. Can we overload a method of base class in derived classes? - Yes
42. Can I have abstract sealed class? I said no(Asked me to explain why I said no){No use in creating such class}
43. Can I have private method signatures in Interface? --- NO It is public by default and can’t be changed
44. What do you mean by AJAX? Advantage of using AJAX
45. What is ENUM?
46. What is the difference between Array and Array List? Dynamic memory
47. Can I have a single Array with different datatypes?
48. Can I have a single ArrayList with different types of objects?
49. Explain delegate (better to give example)
50. What is the use of private constructor - It will not allow the instantiation of the object (new)
51. What is aggregation
52. How is caching done
53. What is the purpose of global.asax file
54. What are the # of pages/forms you have developed in your career (strange question)
55. What is the purpose of sealed keyword
56. Have you used application blocks? What is the application blocks used.
57. What are web services
58. What is the difference between String and String Builder
59. What will happen if a class is implementing multiple interfaces which have same methods?
60. What is an abstract class?
61. What is an interface?
62. Explain when to choose one over the other (interface and abstract class).
63. Explain briefly Garbage collection in .Net?
64. Can you explicitly call garbage collection?
65. What is the difference between public, internal and protected modifiers?
66. What are value and reference types? (were not asked but expected questions)
67. What is boxing/unboxing? (were not asked but expected questions)
68. State the advantages n disadvantages of Array & ArrayList
69. Do we need to manually deallocate memory in .Net (Garbage Collection) (GC.Collect(), GC.SuppressFinalize())
70. Namespace used by generics?
71. Does C# support multi level inheritance?
72. What happens if a class implements 2 interfaces having same method?
73. What happens if a class has private constructor?
74. Have you worked on web services?
75. What is boxing and unboxing?
76. Can an abstract class contain an abstract method?
77. Can an interface contain member variables?
78. What access specifies are there in .net?
79. What is internal keyword?
80. What is encapsulation? In a class, we have a variable called varIlist, and some method is returning this variable, do you think is it breaking the Encapsulation?
81. What is interface inheritance?
82. What is overriding and overloading?
83. What is aggregation and composition?
84. What is web service? What are WSDL, DISCO, and UDDI?
85. What are application blocks?
86. What is the use of private constructors and static constructors?
87. Did you work on C# only?
88. Are you familiar with OOPS? What is interface and encapsulation? Give examples
89. What is protected and private in C#?
90. What is garbage collection? Need for GC?How do you force GC?
91. Can protected /sealed be used in interface?
92. What are destructors?
93. There is one class A with its constructor and class B with its constructor. Class B inherits Class A. Does constructor of Class A get called?
94. Which areas (front tier,DB,middle) are you comfortable?
95. Which DB did you work on?
96. What is difference between Response.Redirect and Server.Transfer?
97. What is view state?
98. Which one do you prefer client-side validation, server-side validation?
99. If JavaScript is disabled from browser then how will client side validation fire?
100. What is WSDL?
101. What is association, aggregation and composition
102. What is a DISCO,UDDI?Explain.
103. Can we access private property in derived classes? - No
104. What is polymorphism? Poly - different forms (Overloading & Overriding )
105. Can we overload a method of base class in derived classes? - Yes
106. Can I have abstract sealed class? I said no(Asked me to explain why I said no){No use in creating such class}
107. Can I have private method signatures in Interface? -- I said no (Asked me to explain why I said no){No Access specifies}
108. What do you mean by AJAX? Advantage of using AJAX
109. What is ENUM?
110. What is the difference between Array and Array List? Dynamic memory
111. Can I have a single Array with different datatypes?
112. Can I have a single ArrayList with different types of objects?
113. What is the use of static constructors? Only for initializing static variables.
ADO.NET - Sushma
Two Data Providers supported by the .NET Framework implement the OleDbConnection in the System.Data.OleDB namespace (Properties- ConnectionString, ConnectionTimeout, Database, State, Methods - BeginTransaction, , CreateCommand, Open and Close) and the SqlConnection in the System.Data.SqlClient namespace.
1) Which data object is used for reading?
DataReader object implements the System.Data.IDataReader
Close - Closes the DataReader but not the underlying Connection.
GetSchemaTable - Retrieves a DataTable object with information about the schema for the
current result set.
NextResult - When executing a Command that returns multiple result sets, you must use NextResult( ) to move from one result set to another. This method returns true if there are more result sets.
Read - Loads the next row into the DataReader. This method returns true if there are more rows left to be read.
2) When do you go for data adapter and data reader?
3) Explain the steps for retrieving data using data set?
//Typed Dataset access
string s = dsCustomersOrders1.Customers[0].CustomerID;
//Untyped Dataset access
string s = (string) dsCustomersOrders1.Tables["Customers"].Rows[0]["CustomerID"];
Strongly typed DataSets are a collection of classes that inherit from the DataSet, DataTable, and
DataRow classes, and provide additional properties, methods, and events based on the DataSet
schema.
4) Is it possible to read information to & fro using data reader?
No, Forward-only
5) What is the difference between Connection.Close() and Connection.Dispose()?
Closes the SqlConnection obj. Dispose closes and releases all the unmanaged resources associated with the Conn obj
6) What are the basic objects in ADO.Net
DataAdapter, DataReader, Command, Connection
Connection (Connects to the data source), Command (Executes commands against the data
source), DataReader (A forward-only, read-only connected result set), Parameter (Defines
parameters for parameterized SQL statements and stored procedures), Transaction (Groups
statements modifying data into work units that are either committed in their entirety or cancelled)
and DataAdapter (Bridges the connected components to the disconnected components, allowing
a DataSet and DataTable to be filled from the data source and later reconciled with the data source).
Example:
string SQL = "SELECT ContactName FROM Customers";
// Create ADO.NET objects.
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(SQL, con);
SqlDataReader dr = null;
// Execute the command.
try
{
con.Open();
dr = cmd.ExecuteReader();
// Iterate over the results.
while (dr.Read())
{
Console.WriteLine(dr ["ContactName"]);
}
}
catch (Exception e)
{
Console.WriteLine(err.ToString());
}
finally
{
if (dr != null) dr.Close();
con.Close();
}
7) What are DataAdapter?
Set of objects used to communicate between a data source and a dataset. That means reading data from a database into a dataset, and then writing changed data from the dataset back to the database.
Adapter supports the following four properties:
_ SelectCommand - reference to a command (SQL statement or stored procedure
name) that retrieves rows from the data store.
_ InsertCommand - reference to a command for inserting rows into the data store.
_ UpdateCommand - reference to a command for modifying rows in the data store.
_ DeleteCommand - reference to a command for deleting rows from the data store.
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM orders", sConnectionString);
Note: No connection open(), close() for data adapter
Example:
// connection string and the select statement
String sConnString = "”;
String sSelectSQL = "SELECT * FROM Orders";
SqlDataAdapter da = new SqlDataAdapter(sSelectSQL, sConnString);
// create a new DataSet to receive the data
DataSet ds = new DataSet();
// read all of the data from the orders table and loads it into the
// Orders table in the DataSet
da.Fill(ds, "Orders");
Design Patterns
114. Explain Singleton pattern
115. What is MVC pattern? Explain.
116. What is MVC Patter? Does Asp.NET/C#.NET is suitable for implanting the MVC?
117. What is Singleton pattern? When do you use?
118. What is Factory method design pattern?
Project Management questions:
119. How do you manage projects in an onsite offshore environment?
120. How do you allocate work between onsite and offshore?
121. What type of job do you prefer onsite to do?
122. How do you manage remotely?
123. Have you experienced situations where client team members were not favorable to offshoring? How did / would you work around it?
124. Have you maintained project plans, change management process etc?
125. Have you worked in development projects or production support? ( highlight atleast one development project, they are keen on expsoure to full SDLC cycle).
Processes/Patterns related questions: UML - Sushma
UML is an open method used to specify, visualize, construct and document the artifacts of an object-oriented software-intensive system under development.UML offers a standard way to write a system's blueprints.
Two different views:
Static (or structural) view: static structure of the system using objects, attributes, operations and relationships. The structural view includes class diagrams and composite structure diagrams
Dynamic (or behavioral) view: Emphasizes the dynamic behavior of the system by showing collaborations among objects and changes to the internal states of objects. This view includes sequence diagrams, activity diagrams, use case diagrams and state machine diagrams
http://en.wikipedia.org/wiki/Unified_Modeling_Language#Unified_Modeling_Language_topics
126. Do you know use cases? Have you heard about RUP? - If you have theoretical knowledge, you can mention that you have been trained by Cognizant and sound confident
127. Have you worked in a water fall model project or a iterative model?
Iterative development slices the deliverable business value (system functionality) into iterations. In each iteration a slice of functionality is delivered.
Waterfall development completes the project-wide work-products of each discipline in a single step before moving on to the next discipline in the next step. Business value is delivered all at once, and only at the very end of the project.
128. What are the different UML diagrams you have used?
Sequence, Activity, Use case, Class diagrams.
129. What is Use Case diagram and what are its main components
Actors & usecase (actions done by the system)
Relationships (include, extend, generalization)
130. Give any example for exception work flow in the use case?
131. Tell me about sequence diagrams?
A sequence diagram shows, as parallel vertical lines ("lifelines"), different processes or objects that live simultaneously, and, as horizontal arrows, the messages exchanged between them, in the order in which they occur.
Simply, different obj’s communication. Live obj - dotted vertical lines, messages - horizontal lines.
132. Explain n-tier architecture?
A multilayered software architecture is using different layers
The concepts of layer and tier are often used interchangeably. However, one fairly common point of view is that there is indeed a difference, and that a layer is a logical structuring mechanism for the elements that make up your software solution, while a tier is a physical structuring mechanism for the system
Three-tier or multi-tier or n-tier is a client-server architecture in which the user interface, functional process logic ("business rules"), computer data storage and data access are developed and maintained as independent modules, most often on separate platforms.
133. What are the different types of test cases that should be covered
( positive
negative
exception)
134. What is a basic flow (in terms of UML)? --- Sequence of steps the occur.
Technical questions:
8) Every system has some entities, so as a developer how would you identify them?
9) Explained me a scenario of information being redundant with in entities, so as a developer what would be the work around? (Related to inheritance and abstract class).
10) Does u prefer to have a web method with 3 parameters or single parameter which is in XML format?
11) In which kind of applications would you like to work?(windows, web)
12) What are the advantages/disadvantages of windows and web applications?
XML, XSD, DTD, HTML, XPath, XQuery - Sushma
1. Where did you use XML, XSL, and XSLT?
2. What is the difference between DTD and XSD?
3. What is XML
4. What is XSL
5. What is XSLT
6. What is XPath
7. Is xml case sensitive - Yes.
No comments:
Post a Comment