Best Online Resource For Non-Resident Indians      SEARCH COOLNRI.COM
 HOME  FORUMS  PORTALS & REVIEWS  RECIPES  INDIAN RESTAURANTS  GROCERY  CLASSIFIEDS  MOVIES / TV  CHAT  NEWS  HOROSCOPE  PAINTINGS  CONTACT  LOGIN
Welcome Guest Search | Active Topics | Members | Log In | Register

C#.Net Interview Questions Part 1 Options
kittusandakinni
Posted: Saturday, May 23, 2009 11:11:59 PM
Rank: Member
Groups: Member

Joined: 3/8/2008
Posts: 5
1. What standard types does C# use?


C# supports a very similar range of basic types to C++, including int, long, float, double, char, string, arrays, structs and classes. In C# Types The names may be familiar, but many of the details are different. For example, a long is 64 bits in C#, whereas in C++ the size of a long depends on the platform (typically 32 bits on a 32-bit platform, 64 bits on a 64-bit platform). Also classes and structs are almost the same in C++ – this is not true for C#. Finally, chars and strings in .NET are 16-bit (Unicode/UTF-16), not 8-bit like C++.


2.What is the syntax to inherit from a class in C#?


Place a colon and then the name of the base class.

Example: class DerivedClassName: BaseClassName


3.How can I make sure my C# classes will interoperate with other .Net languages?


Make sure your C# code conforms to the Common Language Subset (CLS). To help with this, add the [assembly: CLSCompliant (true)] global attribute to your C# source files. The compiler will emit an error if you use a C# feature which is not CLS-compliant.


4.Does C# support variable argument on method?


The params keyword can be applied on a method parameter that is an array. When the method is invoked, the elements of the array can be supplied as a comma separated list.So, if the method parameter is an object array,

void paramsExample(object arg1, object arg2, params object[] argsRest)

{ foreach (object arg in argsRest)

{

/* …. */

}

}

then the method can be invoked with any number of arguments of any type.paramsExample(1, 0.0f, “a string”, 0.0m, new UserDefinedType());


5.What’s the difference between const and readonly?


Readonly fields are delayed initalized constants. However they have one more thing different is that; When we declare a field as const it is treated as a static field. where as the Readonly fields are treated as normal class variables.const keyword used ,when u want’s value constant at compile time but in case of readonly ,value constant at run timeForm the use point of view if we want a field that can have differnet values between differnet objects of same class, however the value of the field should not change for the life span of object; We should choose the Read Only fields rather than constants.Since the constants have the same value accross all the objects of the same class; they are treated as static.



6.What is the difference about Switch statement in C#?


No fall-throughs allowed. Unlike the C++ switch statement, C# does not support an explicit fall through from one case label to another. If you want, you can use goto a switch-case, or goto default.

case 1:

cost += 25;

break;

case 2:

cost += 25;

goto case 1;


7. What is the difference between a static and an instance constructor?


An instance constructor implements code to initialize the instance of the class. A static constructor implements code to initialize the class itself when it is first loaded.


8. Assume that a class, Class1, has both instance and static constructors. Given the code below, how many times will the static and instance constructors fire?


Class1 c1 = new Class1();

Class1 c2 = new Class1();

Class1 c3 = new Class1();


By definition, a static constructor is fired only once when the class is loaded. An instance constructor on the other hand is fired each time the class is instantiated. So, in the code given above, the static constructor will fire once and the instance constructor will fire three times.


9. In which cases you use override and new base?


Use the new modifier to explicitly hide a member inherited from a base class. To hide an inherited member, declare it in the derived class using the same name, and modify it with the new modifier.


10.You have one base class virtual function how will you call the function from derived class?


class a

{

public virtual int m()

{

return 1;

}

}

class b:a

{

public int j()

{

return m();

}

}


11. Can we call a base class method without creating instance?


It is possible if it’s a static method.

It is possible by inheriting from that class also.It is possible from derived classes using base keyword.


12. What is Method Overriding? How to override a function in C#?


Method overriding is a feature that allows you to invoke functions (that have the same signatures) that belong to different classes in the same hierarchy of inheritance using the base class reference. C# makes use of two keywords: virtual and overrides to accomplish Method overriding. Let’s understand this through small examples.

P1.cs

class BC

{

public void Display()

{

System.Console.WriteLine(”BC::Display”);

}

}

class DC : BC

{

new public void Display()

{

System.Console.WriteLine(”DC::Display”);

}

}

class Demo

{

public static void

Main()

{

BC b;

b = new BC();

b.Display();

}

}

Output : BC::Display


13. What is an Abstract Class?


A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.


14.When do you absolutely have to declare a class as abstract?


1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.

2. When at least one of the methods in the class is abstract.


15. What is an interface class?


Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes.


16.Can you inherit multiple interfaces?


Yes. .NET does support multiple interfaces.

Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

COOLNRI.COM 2006-2011 |  TERMS OF USE |  PRIVACY STATEMENT |  SEARCH 
ProjectGlide - Free Effective Project Management