1. Are C# constructors inherited?
No. C# constructors cannot be inherited.
2.Are C# parameters passed by reference or by value?
Default By value
3.Can a property have different get and set access?
Previous version of .net 2.0 nofor others we can have.
4.Can const and static be used together?
No. constant are implicitly static declaring again as static leads confusion
5.Can I directly call a native function exported from a DLL?
Yes.
The following example uses the minimum requirements for declaring a C# method implemented in a native DLL.
using System.Runtime.InteropServices;
class Test{ [DllImport("user32.dll")]
public static extern int MessageBoxT (int h, string m, string c, int type);
public static int Main()
{ return MessageBoxT(0, "Hello, World!", "Title", 0); }
}
The method Test.MessageBoxT() is declared with static and external modifiers. And, it has the DllImport attribute which notifies the compiler that the implementation comes from the user32.dll under the default name of MessageBoxT.
6.How can I force garbage collection?
GC.Collect()
7.How can I output simple debugging messages?
Trace.write methods of Syste.diagnostics class
8.How can one constructor call another?
To call one C# constructor from another, before the body of the constructor, use either:
: base (parameters)to call a constructor in the base class; or:
: this (parameters)
9. How check the object type at runtime?
The is keyword is used for this purpose.
Isinteger
10.How can type name clashes be resolved?
The C# using keyword can be used to supply hints to the C# compiler regarding the fully qualified names of types residing in a specified source (.cs) file. The using keyword can include an alias which can be used to prevent or resolve name clashes.
11.How do destructors work in C#?
A destructor is a method that is called when an object is destroyed—it's memory is marked unused. In .NET, the Garbage Collector (GC) performs much of this type of work automatically
12.How do I declare an out variable?
An out parameter is used to return a value in the same variable which was passed in as a parameter to the method. Any changes made to the parameter are reflected in the variable
13.How do I get DllImport to work?
Reference System.Runtime.InteropServices. Mark all methods with the DllImport attribute as public static extern.
14.How do I make a C# DLL?
Use the /target:library compiler option.
In Visual Studio,
open the Project File's property page;
open CommonProperties -> General -> Output Type;
change the output type to class library;
build the application to create a .dll file.
15.How do I use trace and assert?
Checks for a condition; if the condition is false, displays a message box that shows the call stack.
16.How get the type name at runtime?
To get the name of a C# type at runtime, use the GetType() method of object class.
17.How keep a local variable in scope across a try-catch block?
Decalre outside try block
18.How make sure C# classes will interoperate with other .NET languages?
Ensure that the C# application code conforms to the CLS.To help achieve compliance, add the [assembly:CLSCompliant(true)] global attribute to all C# source files. This attribute will cause the C# compiler to throw an error if a non-CLS-compliant feature is used.
19.How perform a case insensitive string comparison?
Stirng.compare()
20.How do you declare Global variables?
Using session variables.
21.What is a type alias?
C# defines a number of aliases for intrinsic CLR types. Aliases and types can be used interchangably. They can be mixed together in a single statement
22.What is the difference between const and static readonly?
The value of a static readonly field is set at runtime; therefore, the value can be modified by the containing class. On the other hand, the value of a const field is set to a compile-time constant.
22.What is the difference between delegate and event?
An event offers more restricted access than a delegate. When an event is public, other classes are only able to add or remove handlers for that event: such classes cannot—necessarily—fire the event, locate all the handlers for it, or remove handlers of which they are unaware.
23.What is the difference between GetType() and typeof? ?
GetType() Operates on object
Typeof Operates on type
24.What is the difference between the out and ref parameter modifiers?
Both the out and ref modifiers can be applied to method arguments. And, both imply that the argument will be passed by reference—either as a reference to a value type variable or to a reference type variable. However, the out parameter enables passing in an uninitialized variable and guarantees that it will come back with set to a value.
Thursday, January 28, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment