Detailed Explanation of C #

A: Conditional: characteristic condition, a condition predefined method.
Use method:
[the Conditional ( "the DEBUG")]
public void Test ()
{
MessageBox.Show ( "XXXX");
Console.WriteLine ( "XXXXXXX");
}
above characteristics represented: only in Debug mode, which will be called method.

Two: Obsolete: This predefined characteristics tagged entities should not be used by the program. It allows you to tell the compiler to discard a particular target element. For example, when a new method is used in a class, but you still want to keep the old methods in the class, you can display a new method should be used, rather than the old method of the message to mark it as obsolete (outdated of).

public class MyClass
{
[Obsolete("Don't use OldMethod, use NewMethod instead", true)]
static void OldMethod()
{
Console.WriteLine("It is the old method");
}
static void NewMethod()
{
Console.WriteLine("It is the new method");
}
public static void Main()
{
OldMethod();
}
}

Three: DllImport: .NET used to mark a non-function, that the method is defined in an external DLL.
[The DllImport ( "the User32.dll")]
public static extern int the MessageBox (int Here hParent, the Message String, String the Caption, the Type int);

static void Main(string[] args)
{
DisplayRunningMessage();
DisplayDebugMessage();
MessageBox(0,"Hello","Message",0);
Console.ReadLine();
}

Guess you like

Origin www.cnblogs.com/LCLBook/p/11857989.html