C# (Sharp) Programming Language

  Home  Microsoft .Net Technologies  C# (Sharp) Programming Language


“Learn C# (Sharp) Programming Language by Interview Questions and Answers”



163 C# (Sharp) Programming Language Questions And Answers

43⟩ How do you mark a method obsolete?

[Obsolete] public int Foo() {...}

or

[Obsolete("This is a message describing why this method is obsolete")] public int Foo() {...}

Note: The O in Obsolete is always capitalized.

 236 views

51⟩ 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.

 190 views

54⟩ Explain ACID rule of thumb for transactions in C#.

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.

 194 views

58⟩ 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.

 212 views

60⟩ How do you directly call a native function exported from a DLL?

Here’s a quick example of the DllImport attribute in action:

using System.Runtime.InteropServices;

class C

{

[DllImport("user32.dll")]

public static extern int MessageBoxA

(int h, string m, string c, int type);

public static int Main()

{

return MessageBoxA(0, "Hello World!", "Caption", 0);

}

}

This example shows the minimum requirements for declaring a C# method that is implemented in a native DLL. The method C.MessageBoxA() is declared with the static and external modifiers, and has the DllImport attribute, which tells the compiler that the implementation comes from the user32.dll, using the default name of MessageBoxA. For more information, look at the Platform Invoke tutorial in the documentation.

 212 views