Breaking News

Editors Picks

Showing posts with label C# Interview Question And Answer. Show all posts
Showing posts with label C# Interview Question And Answer. Show all posts

Sunday, August 8, 2010

C# interview Question And Answer

C# interview Question-and answer


1) What’s the advantage of using System.Text.StringBuilder over System.String?
Strings are object which cannot be modified once created. Each time when the string is operated an instance for the object is created. String builder is more efficient then the system.string while manipulating on string.

2) Can you store multiple data in System.Array?
Using System.Array to store multiple data types is not possible. In case if the user is willing to store in multiple data types they can make use of array list.

3) What’s a delegate?
A delegate is a type-safe object which can point to another method or multiple methods in the application.
A delegate consist of
Method name
Argument (if any)
Return value (if any)

4) What is hashtable?
Hashtable is a .NET datatype that helps in retrieval of data using a unique key.

5) Can multiple catch blocks be executed?
It is not possible to execute multiple catch block. Since once the catch code fires the controlled is automatically pass to the final code and the final code starts execution.

6) What are advantages of Microsoft-provided data provider classes in ADO.NET?
It is able to handle single tier to multi-tier.
Provides data security.
They perform task faster.

7) What is an interface class?
Interface class specify the methods, properties and events but they don’t provide implementation as like classes. The implementation is done by the class and are defined as separate entity from classes.

8) Can you inherit multiple interfaces?
Multiple interface cannot be implemented using .NET. since .NET doesn’t support interface.

9) What is an abstract class?
Abstract class is a class that cannot be instantiated. It is a class to be inherited and the methods to be overridden.

10) What’s a multicast delegate?
A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called.

11) What does the term immutable mean?
Immutable refers to data values which cannot be changed.

12) What is difference between of the C and C#?
C is not case sensitive but C# is sensitive.
C# focus more on design and C is on function.
C# is object oriented and C is structured language.
C# is type safe but C is not.

13) What is the difference between C# and java?
Java is cross platform language and C# is window specific language.
C# relies on windows system foundation whereas java rely on java virtual machine.
JVM converts byte code into executable code. C# converts into MSIL.

14) What is the syntax to inherit from a class in C#?
Class newclass: baseclass
Class can be inherited by placing the class name after the colon.

15) What is Microsoft.Access?
Microsoft.Access is used to connect to database inorder to access them.

16) How to Do File Exception Handling in C#?
Exception handling is a built in mechanism in .NET framework. It enables to identify errors and to handle run time errors. They contain lot of standard exception.

17) What’s the difference between // comments, /* */ comments and /// comments?
// comment is used to said single comment.
/* */ Comment is used for multiple line comment.
/// comment is for XML documentation comment.

18) How can you sort the elements of the array in descending order?
Sorting the elements in the descending order can be done by the function sort() and the reverse() method.

19) How’s the DLL Hell problem solved in .NET?
Assembly versioning specify the library that required by the application to run and also the version of the library to the application.

20) What is the use of serializable keyword in C#?
Declaring a class with the keyword serializable enables the object to be serialized mainly for exchange of data between two system. If the object going to inherit by any other object then serialization downstream required to be used.

21) Pointers in c#?
C# supports pointers but it required to be specified within the unsafe code.
For example
Unsafe
{
// usage of pointers
}

22) How does C# implement events?
C# implements events by the following:-
Pointers
Delegates
DLLs

23) What does assert() do?
Assert taken the parameter in Boolean condition, while debugging it shows the error dialog when the condition fails. If the condition true the program proceeds without any interruption.

23) What is the name of C#.NET compiler?
C#.NET compiler is JIT(Just in time) compiler.

24) What is true about readonly variable in C# code?
Read only file is to be initialized at the time of the construction of the object.

25) What is shadowing?
Shadowing is a VB.NET concept which can implement base class without overriding the members of the class. Any class member can be shadowed by using the keyword SHADOW.

C# interview Question-and answer


1) What is a process and threads?
A process is an entity which has its own memory space and maintain state information.
Thread is an independent execution path, able to run simultaneously with other threads.

2) What is an indexer in C#?
A special kind of operator overloading is indexer(). Once the indexer has been defined the class object can be defined using array syntax.

3) What is the advantage of using generics in C#?
It is not required to test on data types
It performs sorting much better
Generic delegates can also be used in dynamically generated code without requiring the generation of a delegate type.

4) What is the advantage of using delegates in C#?
They are managed function pointers.
They are type checked and held in spaces that can be reclaimed by the memory manager.

5) Code written in C# can not used in which of the languages?
Code written in C# cannot be used in java.

6) what is object pooling?
The great advantage of using .NET is that it helps to write code to pool objects and threads. Object pooling is mainly to share objects between different clients.

7) Explain about 'this' and where and when it should be used?
This keyword is used to refer to the current class instance. It provides support while debugging.

8) What is a pre-requisite for connection pooling?
All the process should accept to share the same connection, parameters and including the settings.

9) Explain ACID rule of thumb for transactions?
All transaction to be automatic, each single unit should be independent, consistent, durable and isolated.

10) What is IL?
IL stands for Intermediate language. C# compiler converts the program into intermediate language.

11) Is it possible to have different access modifiers on the get/set methods of a property?
No, it is not possible to have different access modifier. If the user require to have different modifier then they can create by making the property internal and create internal method separate from property.

12) How to compare two strings in C#?
In general strings can be compared using == and != operators. The following comparison can be done in C# using the following if ((object) str1 == (object) str2) { }.


13) What do you know about .NET assemblies?
Assemblies are smallest unit based on which the development and deployment of .NET application possible. They are also known as the building block of an progam.

14) How do you mark a method absolete?
[Obselete] public int Spy{} {..}

15) How is method overriding different from overloading?
In overriding you change the behavior of a derived class. Overload is to have the same method name within the class.

16) What is boxing?
Encapsulating a copy of a value type in an object is termed as boxing.

17) How does assembly versioning in .NET prevent DLL Hell?
.NET allows assemblies to specify the name AND the version of any assemblies they need to run.

18) What is the difference between const and static read-only?
The major difference is that static variable can be modified by the class which contains it whereas a variable declared const cannot be changed.

19) Explain the three services model commonly know as a three-tier application.
Presentation
Business
Data

20) How do I convert a string to an int in C#?
using System;
class conversion
{
public static void Main()
{
String s1 = "100";
int y = Convert.ToInt32(s1);
Console.WriteLine(y);
}
}

21) Does C# support templates?
No, C# doesn’t support templates. They support a type of template known as generic. It has a similar syntax but instantiated during run time.

22) Why does my Windows application pop up a console window every time I run it?
The properties setting should be in windows application and not console application.

23) Does C# support C type macros?
C# doesn’t support c type macros. Some of the predefined C macros is also defined in macros, but they will be useful in debug time.

24) Can you declare the override method static while the original method is non-static?
Signature of the virtual method remains the same. The virtual keyword alone is changed to override.

25) How can I get the ASCII code for a character in C#?
Casting the char to an int will give you the ASCII value:
char c = 'f';
System.Console.WriteLine((int)c);
If you what to get a char ASCII value which is in a string then the following syntax can be used:
For Example:- S= Programming
System.Console.WriteLine((int)s[3]);//s[3] returns the ACSII value of ‘g’
The base class libraries also offer ways to do this with the Convert class or Encoding classes if you need a particular encoding.


C# interview Question and answer


1. Explain the three services model commonly know as a three-tier application.
The three service model in three tier application are
Data
Business
Presentation


2. what are the rules to be followed while naming variable in C#?
The following are the rules to be followed
It should be unique
It can have any number of character
Shouldn't use keyword as names
It should start with letter or underscore.

3. What are the different types of Data?
C# supports two types of data:-
Value type: - Value type directly contains the data. Once the variable declared the system allocates memory to store value
Reference type: - They don't contain variable rather the reference to the variable.

4. Explain about comment entry?
Comments is also a part of the program that explains about the code. Compilers ignore the comments. comments are enclosed within '/* and */.

5. Explain about protected internal access specifier?
internal access specifier will hide the member function and variables to be accessed by other function and objects, other then the child class. It plays an important role during implementing inheritance.

6. How do you specify a custom attribute for the entire assembly (rather than for a class)?
Global attribute require to appear on top level and before the namespace specification.
For eg:-
using System;
[assembly : MyAttributeClass] class X {}

7. How do you mark a method obsolete?
[Obsolete] public int x1() {...}
Obsolete is the keyword used in front of the method to make it obsolete.

8. What do you know about .NET assemblies?
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.

9. What’s the difference between private and shared assembly?
The assembly used inside the application are called as private assembly, they do not require any strong name to be identified.
shared assembly as the name indicates can be used by multiple applications and it is very much essential that it has a strong name.


10. What’s a strong name?
A strong name require to have the following fields:-
assembly,
version number,
culture identity,
public key token.

11. Can you have two files with the same file name in GAC?
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.

12. How can you create a strong name for a .NET assembly?
Strong Name tool (sn.exe) which can be used to create strong name.

13. What is delay signing?
It allows to place a shared assembly by just placing a public key in the assembly. It is more secure and helps the developers to work with strong name and shared assemblies.

14. Is there an equivalent of exit() for quitting a C# .NET application?
System.Environment.Exit is an equivalent of exit() that enables to quit from the application.

15. How do I make a DLL in C#?
target:library compiler option inorder to make a DLL in C#.

16. Is there regular expression (regex) support available to C# developers?
Yes, regular expression are supported by .NET class. System.Text.RegularExpressions namespace provide the expression for regular expression.

17. What connections does Microsoft SQL Server support?
Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords)

18. What is trace and debug in C#?
.NET allows very useful class that help in monitoring the working of the program. Trace and Debug can be very powerful development tools that can help kill hard to find bugs by making them glaringly obvious.

19. What optimizations does the C# compiler perform when you use the optimize+ compiler option?
optimize branches over branches
unreachable code
getting rid of unused locals.

20. How do I create a multi language, multi file assembly?
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.


C# interview Question- and answer


1. How do I declare inout arguments in C#?
The equivalent of inout in C# is ref. , as shown in the following
example:
public void My1 (ref String str1, out String str2)
{
...
}
When calling the method, it would be called like this: String s1;
String s2;
s1 = "Hi";
My1(ref s1, out s2);
Console.WriteLine(s1);
Console.WriteLine(s2);
Notice that you need to specify ref when declaring the function and calling it

2. Can you change the value of a variable while debugging a C# application?
Yes, you can change the value of a variable while debugging a C# application.

3. What is the difference between const and static read-only?
static read only can be modified by class that containing whereas const can never be modified.

4. What namespaces are necessary to create a localized application?
System.Globalization, System.Resources

5. How do you inherit from a class in C#?
Place a colon and then the name of the base class.

6. Does C# support parametrized properties?
C# does not support parametrized properties. However it supports the concept of indexer. An indexer is a member which enables the object to be indexed as in array.

7. Does C# support C type macros?
C# doesn't support C type macros. Some of the C macros are found in .NET class but they only work with debug builds.

8. How do I convert a string to an int in C#?
Convert.ToInt32 is the keyword to be used to convert string to int.
For eg:-
class ConvStrtoInt
{
public static void Main()
{
String str = "2345";
int x = Convert.ToInt32(str);
Console.WriteLine(x);
}
}

9. What is the .NET datatype that allows the retrieval of data by a unique key?
HashTable is the datatype to be used to retrieve data by unique key.

10. What is the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

11. How can I get the ASCII code for a character in C#?
Casting the char to an int will give you the ASCII value: char c = 'f'; System.Console.WriteLine((int)c); or for a character in a string: System.Console.WriteLine((int)s[3]); Even the base class libraries also offer ways to do this with the Convert class or Encoding classes if you need a particular encoding.

12. How do I create a Delegate/MulticastDelegate?
C# requires only a single parameter for delegates: the method address. Unlike other languages, where the programmer must specify an object reference and the method to invoke, C# can infer both pieces of information by just specifying the method's name.
For example,
System.Threading.ThreadStart: Foo MyFoo = new Foo();
ThreadStart del = new ThreadStart(MyFoo.Baz);

13. How do you debug an ASP.NET Web application?
Attach the aspnet_wp.exe process to the DbgClr debugger.

14. What are the ways to deploy an assembly?
Some of the ways to deploy assembly are as follows:-
MSI installer
XCOPY
CAB archive

15. Difference between imperative and interrogative code.
There are imperative and interrogative functions. Imperative functions are the one which return a value while the interrogative functions do not return a value.

16. Difference between imperative and interrogative code.
There are imperative and interrogative functions. Imperative functions are the one which return a value while the interrogative functions do not return a value.

17. Explain manifest & metadata?
Manifest is metadata about assemblies. Metadata is machine-readable information about a resource, or “”data about data.” In .NET, metadata includes type definitions, version information, external assembly references, and other standardized information.

18. Difference between value and reference type. what are value types and reference types?
Value type - bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort
Value types are stored in the Stack
Reference type - class, delegate, interface, object, string
Reference types are stored in the Heap

19. What are the two kinds of properties.
Two types of properties in .Net: Get and Set

20. What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
Read more ...

Sunday, June 27, 2010

Difference between abstract class and interface

1)

Interfaces provide a form of multiple inheritance. A class 
can extend only one other class. 
Interfaces are limited to public methods and constants with 
no implementation. Abstract classes can have a partial 
implementation, protected parts, static methods, etc. 
A Class may implement several interfaces. But in case of 
abstract class, a class may extend only one abstract class. 
Interfaces are slow as it requires extra indirection to to 
find corresponding method in in the actual class. Abstract 
classes are fast.

2)
(1)       An abstract class may contain complete or 
incomplete methods. Interfaces can contain only the 
signature of a method but no body. Thus an abstract class 
can implement methods but an interface can not implement 
methods.
(2)         An abstract class can contain fields, 
constructors, or destructors and implement properties. An 
interface can not contain fields, constructors, or 
destructor and it has only the property's signature but no 
implementation.
(3)         An abstract class cannot support multiple 
inheritance, but an interface can support multiple 
inheritance. Thus a class may inherit several interfaces 
but only one abstract class.
(4)         A class implementing an interface has to 
implement all the methods of the interface, but the same is 
not required in the case of an abstract Class.
(5)       Various access modifiers such as abstract, 
protected, internal, public, virtual, etc. are useful in 
abstract Classes but not in interfaces. 
(6)         Abstract classes are faster than interfaces.

3)

Interface :
1.Interface have only Signature.
2.All the Methods are Public , It doesn't have access Modifier Controls
3.It have used Multiple inheritence in the Object oriented Language
4.All the Methods are Abstract.
5.It does not have Contructor,destructor,Fileds
6.A Class May inherits several Interfaces

Abstract Class:
1.Abstract Class have Method defination and Implementation
2.It have control the Access Modifiers
3.It does not allow multiple Inheritence
4.Some methods are concrete
5. It have Contructor and destructor
6.Only one abstract have to derived 


4)

class, we make use of the abstractkeyword. Such a class cannot be instantiated. Syntax below:
abstract public class Vehicle { } 
Above, an abstract class named Vehicle has been defined. We may use the fields, properties and member functions defined within this abstract class to create child classes like Car,Truck, Bike etc. that inherit the features defined within the abstract class. To prevent directly creating an instance of the class Vehicle, we make use of the abstract keyword. To use the definitions defined in the abstract class, the child class inherits from the abstract class, and then instances of the Child class may be easily created. Further, we may define abstract methods within an abstract class (analogous to C++ pure virtual functions) when we wish to define a method that does not have any default implementation. Its then in the hands of the descendant class to provide the details of the method. There may be any number of abstract methods in an abstract class. We define an abstract method using the abstract keyword. If we do not use the abstract keyword, and use the virtual keyword instead, we may provide an implementation of the method that can be used by the child class, but this is not an abstract method. Remember, abstract class can have an abstract method, that does not have any implementation, for which we use the abstract keyword, OR the abstract class may have a virtual method, that can have an implementation, and can be overriden in the child class as well, using the override keyword. Read example below
Example: Abstract Class with Abstract method namespace Automobiles {  public abstract class Vehicle  {   public abstract void Speed() //No Implementation here, only definition  } } Example: Abstract Class with Virtual method namespace Automobiles {  public abstract class Vehicle  {   public virtual void Speed() //Can have an implementation, that may be overriden in child class   {     ...   }  } Public class Car : Vehicle { Public override void Speed()   //Here, we override whatever implementation is there in the abstract class   {    ... //Child class implementation of the method Speed()  } } }
An Interface is a collection of semantically related abstract members. An interface expresses through the members it defines, the behaviors that a class needs to support. An interface is defined using the keyword interface. The members defined in an interface contain only definition, no implementation. The members of an interface are all public by default, any other access specifier cannot be used. See code below:
Public interface IVehicle //As a convention, an interface is prefixed by letter I {   Boolean HasFourWheels() }
Time to discuss the Difference between Abstract Class and Interface 1) A class may inherit only one abstract class, but may implement multiple number of Interfaces. Say a class named Car needs to inherit some basic features of a vehicle, it may inherit from an Aabstract class named Vehicle. A car may be of any kind, it may be a vintagecar, a sedan, a coupe, or a racing car. For these kind of requirements, say a car needs to have only two seats (means it is a coupe), then the class Car needs to implement a member field from an interface, that we make, say ICoupe. 2) Members of an abstract class may have any access modifier, but members of an interface are public by default, and cant have any other access modifier. 3) Abstract class methods may OR may not have an implementation, while methods in an Interface only have a definition, no implementation.
Read more ...

What is difference between dll and exe?

1) 

.Exe
1.These are outbound file.
2.Only one .exe file exists per application.
3. .Exe cannot be shared with other applications.

.dll
1.These are inbund file .
2.Many .dll files may exists in one application.
3. .dll can be shared with other applications.


2)
EXE..
1.Its a executable file
2.There is only single main entry
3.When a system launches new exe, a new process is created
4.The entry thread is called in context of main thread of that process.

DLL..
1.Its a Dynamic Link Library
2.There are many entry points.
3.The system loads a DLL into the context of an existing thread



3)
DLL

1. It can be reused.
2. It can be versioned.
3. It is not self executable
4. It doesn't have main function

.EXE
1. It cannot be reused
2. It cannot be versioned.
3. It is self executable.
4. It will have main
function.

D


4)

DLL:
1)it has versioning
2)it is not self executable
3)it runs in application process memory
4)it has no entry point
5)it is reusable

Exe:
1)it is self executable
2)it has no versioning
3)it runs in own memory
4)it have main function(Entry point)
5)it is self executable
5)

DLL:
1)it has versioning
2)it is not self executable
3)it runs in application process memory
4)it has no entry point
5)it is reusable
6)Out Process Server

Exe:
1)it is self executable
2)it has no versioning
3)it runs in own memory
4)it have main function(Entry point)
5)it is self executable
6) In Process Server
Read more ...

Friday, June 25, 2010

Object Oriented Programming? (oops)

What is Object Oriented Programming?

It is a problem solving technique to develop software systems. It is a technique to think real world in terms of objects. Object maps the software model to real world concept. These objects have responsibilities and provide services to application or other objects.

What is a Class?

A class describes all the attributes of objects, as well as the methods that implement the behavior of member objects. It is a comprehensive data type which represents a blue print of objects. It is a template of object.

What is an Object?

It is a basic unit of a system. An object is an entity that has attributes, behavior, and identity. Objects are members of a class. Attributes and behavior of an object are defined by the class definition.

What is the relation between Classes and Objects?

They look very much same but are not same. Class is a definition, while object is a instance of the class created. Class is a blue print while objects are actual objects existing in real world. Example we have class CAR which has attributes and methods like Speed, Brakes, Type of Car etc. Class CAR is just a prototype, now we can create real time objects which can be used to provide functionality. Example we can create a Maruti car object with 100 km speed and urgent brakes.

What are different properties provided by Object-oriented systems?


Following are characteristics of Object Oriented Systems :

Abstraction

It allows complex real world to be represented in simplified manner. Example color is abstracted to RGB. By just making the combination of these three colors we can acheive any color in world. It is a model of real world or concept.

Encapsulation

It is a process of hiding all the internal details of an object from the outside world.

Communication using messages

When application wants to acheive certain task it can only be done using combination of objects. A single object cannot do all the task. Example if we want to make order processing form. we will use Customer object,Order object,Product object and Payment object to acheive this functionality. In short these objects should communicate with each other. This is achieved when objects send messages to each other.

Object lifetime

All objects have life time. Objects are created and initialized necessary functionalities are done and later the object is destroyed. Every object have there own state and identity which differ from instance to instance.


Class hierarchies
In object oriented world objects have relation and hierarchies in between them. There are basically three kind of relationship in Object Oriented World

Association

This is the simplest relationship between objects. Example every customer has sales. So Customer object and sales object have an association relation between them.

Aggregation

This is also called as composition model. Example in order to make a "Accounts" class it has use other objects example "Voucher", "Journal" and "Cash" objects. so accounts class is aggregation of these three objects.

Inheritance

Hierarchy is used to define more specialized classes based on a preexisting generalized class. Example we have VEHICLE class and we can inherit this class make more specialize class like CAR, which will add new attributes and use some existing qualities of the parent class. Its shows more of a parent-child relationship. This kind of hierarchy is called inheritance.

Polymorphism

When inheritance is used to extend a generalized class to a more specialized class, it includes behavior of the top class. The inheriting class often implement a behavior that can be somewhat different than the generalized class, but the name of the behavior can be same. It is important that a given instance of an object use the correct behavior, and the property of polymorphism allows this to happen automatically


What are abstract classes?

Following are features of a abstract class :

You can not create a object of abstract class
Abstract class is designed to act as a base class (to be inherited by other classes). Abstract class is a design concept in program development and provides a base upon which other classes are built.
Abstract classes are similar to interfaces. After declaring an abstract class,it cannot be instantiated on its own,it must be inherited.
In VB.NET abstract classes are created using "MustInherit" keyword. In C# we have "Abstract" keyword.
Abstract classes can have implementation or pure abstract methods which should be implemented in the child class.

What is a Interface?

Interface is a contract that defines the signature of the functionality. So if a class is implementing a interface it says to the outer world, that it provides specific behavior. Example if a class is implementing Idisposable interface that means it has a functionality to release unmanaged resources. Now external objects using this class knowthat it has contract by which it can dispose unused unmanaged objects.

Single Class can implement multiple interfaces.
If a class implements a interface then it has to provide implementation to all its methods
.
What is the difference between abstract classes and interfaces?
Following are the differences between abstract and interfaces :

Abstract classes can have concrete methods while interfaces have no methods implemented.
Interfaces do not come in inheriting chain, while abstract classes come in inheritance.



What is a delegate?
Delegate is a class that can hold a reference to a method or a function. Delegate class has a signature and it can only reference those methods whose signature is complaint with the class. Delegates are type-safe functions pointers or callbacks.

What are events?

As compared to delegates events works with source and listener methodology. So listeners who are interested in receiving some events they subscribe to the source.Once this subscription is done the source raises events to its entire listener when needed. One source can have multiple listeners.

Do events have return type?

No, events do not have return type.

Can events have access modifiers?

Events are always public as they are meant to serve every one registering to it. But you can access modifiers in events. You can have events with protected keyword which will be accessible only to inherited classes. You can have private events only for object in that class.
Can we have shared events?

Yes, you can have shared events note only shared methods can raise shared events.

What is shadowing?

When two elements in a program have same name, one of them can hide and shadow the other one. So in such cases the element which shadowed the main element is referenced.
What is the difference between Shadowing and Overriding?
Following are the differences between shadowing and overriding.

Overriding redefines only the implementation while shadowing redefines the whole element.
In overriding derived classes can refer the parent class element by using "ME" keyword, but in shadowing you can access it by "MYBASE".

What is the difference between delegate and events?

Actually events use delegates in bottom. But they add an extra layer on the delegates, thus forming the publisher and subscriber model.

As delegates are function to pointers they can move across any clients. so any of the clients can add or remove events, which can be pretty confusing. But events give the extra protection by adding the layer and making it a publisher and subscriber model.

If we inherit a class do the private variables also get inherited?

Yes, the variables are inherited but cannot be accessed directly by the class interface.

What are the different accessibility levels defined in .NET?


Following are the five levels of access modifiers :

Private : Only members of class have access

Protected : All members in current class and in derive classses can access the variables.

Friend (internal in C#) : Only members in current project have access to the elements.

Protected friend (protected internal in C#): All members in current project and all members in derived class can access the variables.

Public : All members have access in all classes and projects.

Can you prevent a class from overriding?

If you define a class as "Sealed" in C# and "NotInheritable" in VB.NET you can not inherit the class any further.
What is the use of "MustInherit" keyword in VB.NET?
If you want to create a abstract class in VB.NET it is done by using "MustInherit" keyword. You can not create an object of a class which is marked as "MustInherit". When you define "MustInherit" keyword for class you can only use the class by inheriting.


Do interface have accessibility modifier?

All elements in Interface should be public. So by default all interface elements are public by default.

What are similarities between Class and structure?

Following are the similarities between classes and structures :-

Both can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.

Structures and classes can implement interface.

Both of them can have constructors with and without parameter.

Both can have delegates and events.

What is the difference between Class and structures?

Following are the key differences between them :

Structure are value types and classes are reference types. So structures use stack and classes use heap.

structures members can not be declared as protected, but class members can be. You can not do inheritance in structures.

Structures do not require constructors while classes require.

Objects created from classes are terminated using Garbage collector. Structures are not destroyed using GC.


What does virtual keyword mean?
They signify that method and property can be overridden.


What are shared (VB.NET)/Static(C#) variables?
Static/Shared classes are used when a class provides functionality which is not specific to any instance. In short if you want an object to be shared between multiple instances you will use a static/ Shared class.

Following are features of Static/Shared classes :

They cannot be instantiated. By default a object is created on the first method call to that object.

Static/Shared classes cannot be inherited.

Static/Shared classes can have only static members.

Static/Shared classes can have only static constructor.

What is Dispose method in .NET?

.NET provides "Finalize" method in which we can clean up our resources. But relying on this is not always good so the best is to implement "Idisposable" interface and implement the "Dispose" method where you can put your clean up routines.
What is the use of "OverRides" and "Overridable" keywords?
Overridable is used in parent class to indicate that a method can be overridden. Overrides is used in the child class to indicate that you are overriding a method.
Where are all .NET Collection classes located?
System.Collection namespace has all the collection classes available in .NET.

What is ArrayList?

Array is whose size can increase and decrease dynamically. Array list can hold item of different types. As Array List can increase and decrease size dynamically you do not have to use the REDIM keyword. You can access any item in array using the INDEX value of the array position.

What is a Hash Table?

You can access array using INDEX value of array, but how many times you know the real value of index. Hashtable provides way of accessing the index using a user identified KEY value, thus removing the INDEX problem.


What are queues and stacks?

Queue is for first-in, first-out (FIFO) structures. Stack is for last-in, first-out (LIFO) structures.
What is ENUM?

It is used to define constants.
What is nested Classes?


Nested Classes are classes within classes.

Public Class ClsNested

    Public Class ChildNested

      Public Sub ShowMessage()
      MessageBox.Show(" Hi this is nested class ")
      End Sub

     End Class
End Class

What is Operator Overloading in .NET?

It provides a way to define and use operators such as +,-,and / for user-defined classes or structs. It allows us to define / redefine the way operators work with our classes and structs. This allows programmers to make their custom types look and feel like simple types such as int and string.

What is the significance of Finalize method in .NET?

.NET Garbage collector does almost all clean up activity for your objects. But unmanaged resources(ex: - Windows API created objects, File, Database connection objects, COM objects etc) is outside the scope of .NET framework we have to explicitly clean our resources. For these types of objects .NET framework provides Object. Finalize method which can be overridden and clean up code for unmanaged resources can be put in this section.

How can we suppress a finalize method?

GC.SuppressFinalize()

What is the use of DISPOSE method?

Dispose method belongs to IDisposable interface. If any object wants to release its unmanaged code best is to implement IDisposable and override the Dispose method of IDisposable interface. Now once your class has exposed the Dispose method it is the responsibility of the client to call the Dispose method to do the cleanup.

How do i force the Dispose method to be called automatically, as clients can forget to call Dispose method?

Call the Dispose method in Finalize method and in Dispose method suppress the finalize method using GC.SuppressFinalize.

In what instances you will declare a constructor to be private?

when we create a private constructor, we can not create object of the class directly from a client. So you will use private constructors when you do not want instances of the class to be created by any external client. Example UTILITY functions in project will have no instance and be used without creating instance, as creating instances of the class would be waste of memory.

Can we have different access modifiers on get/set methods of a property?

No we can not have differnent modifiers same property. The access modifier on a property applies to both its get and set accessors.

If we write a goto or a return statement in try and catch block will the finally block execute?
The code in finally always run even if there are statements like goto or a return statements.

What is Indexer?

An indexer is a member that enables an object to be indexed in the same way as an array.
Can we have static indexer in C#?

No


Can two catch blocks be executed?
No, once the proper catch section is executed the control goes finally block. So there will not be any scenarios in which multiple catch blocks will be executed.
What is the difference between System.String and System.StringBuilder classes?
System.String is immutable; System.StringBuilder can have mutable string where a variety of operations can be performed.

Read more ...

Friday, June 11, 2010

ADO.NET and Database Questions

1.    What is the role of the DataReader class in ADO.NET connections? 
It returns a read-only, forward-only rowset from the data source.  A DataReader provides fast access when a forward-only sequential read is needed.
 
2.    What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET? 
SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix.  OLE-DB.NET is a .NET layer on top of the OLE layer, so it’s not as fastest and efficient as SqlServer.NET.
 
3.    What is the wildcard character in SQL? 
Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’.
 
4.    Explain ACID rule of thumb for transactions.
A transaction must be:
1.      
 Atomic - it is one unit of work and does not dependent on previous and following transactions.
2.      
 Consistent - data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t.
3.      
 Isolated - no transaction sees the intermediate results of the current transaction).
4.      
 Durable - the values persist if the data had been committed even if the system crashes right after.
 
5.    What connections does Microsoft SQL Server support? 
Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and password).
 
6.    Between Windows Authentication and SQL Server Authentication, which one is trusted and which one is untrusted? 
Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.
 
7.    What does the Initial Catalog parameter define in the connection string? 
The database name to connect to.
  
8.    What does the Dispose method do with the connection object? 
Deletes it from the memory.
To Do: answer better.  The current answer is not entirely correct.
 
9.    What is a pre-requisite for connection pooling? 
Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings. 
 The connection string must be identical.
 
Assembly Questions
1.    How is the DLL Hell problem solved in .NET? 
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.
 
2.    What are the ways to deploy an assembly? 
An MSI installer, a CAB archive, and XCOPY command.
 
3.    What is a 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.
 
4.    What namespaces are necessary to create a localized application? 
System.Globalization and System.Resources.
 
5.    What is the smallest unit of execution in .NET?
an Assembly.
 
6.    When should you call the garbage collector in .NET?
As a good rule, you should not call the garbage collector.  However, you could call the garbage collector when you are done using a large object (or set of objects) to force the garbage collector to dispose of those very large objects from memory.  However, this is usually not a good practice.
 
7.    How do you convert a value-type to a reference-type?
Use Boxing.
 
8.    What happens in memory when you Box and Unbox a value-type?
Boxing converts a value-type to a reference-type, thus storing the object on the heap.  Unboxing converts a reference-type to a value-type, thus storing the value on the stack.


Read more ...

Events and Delegates and Debugging and Testing and XML Documentation Questions

1.    What’s a delegate? 
A delegate object encapsulates a reference to a method.
 
2.    What’s a multicast delegate? 
A delegate that has multiple handlers assigned to it.  Each assigned handler (method) is called.
 
XML Documentation Questions
1.    Is XML case-sensitive? 
Yes.
 
2.    What’s the difference between // comments, /* */ comments and /// comments? 
Single-line comments, multi-line comments, and XML documentation comments.
 
3.    How do you generate documentation from the C# file commented properly with a command-line compiler? 
Compile it with the /doc switch.
 
Debugging and Testing Questions
1.    What debugging tools come with the .NET SDK?
1.  
 CorDBG – command-line debugger.  To use CorDbg, you must compile the original C# file using the /debug switch.
2.  
 DbgCLR – graphic debugger.  Visual Studio .NET uses the DbgCLR.
 
2.    What does assert() method do? 
In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false.  The program proceeds without any interruption if the condition is true.
 
3.    What’s the difference between the Debug class and Trace class? 
Documentation looks the same.  Use Debug class for debug builds, use Trace class for both debug and release builds.
 
4.    Why are there five tracing levels in System.Diagnostics.TraceSwitcher? 
The tracing dumps can be quite verbose.  For applications that are constantly running you run the risk of overloading the machine and the hard drive.  Five levels range from None to Verbose, allowing you to fine-tune the tracing activities.
 
5.    Where is the output of TextWriterTraceListener redirected? 
To the Console or a text file depending on the parameter passed to the constructor.
 
6.    How do you debug an ASP.NET Web application? 
Attach the aspnet_wp.exe process to the DbgClr debugger.
 
7.    What are three test cases you should go through in unit testing? 
1.       Positive test cases (correct data, correct output).
2.      
 Negative test cases (broken or missing data, proper handling).
3.      
 Exception test cases (exceptions are thrown and caught properly).
 
Can you change the value of a variable while debugging a C# application? 
Yes.  If you are debugging via Visual Studio.NET, just go to Immediate window. 
Read more ...

Contact Us

Name

Email *

Message *