VB programmer C # 4

zhaozj2021-02-08  192

INDEXERS can be regarded as a smart array that you can use Indexers when you want to access an attribute with an array. such as:

Public Double this [intIndex]

Attributes

Attributes refers to an annotation on the source code element, which is the same as the conditional assembly in VB. However, in C #, Attributes information is stored in metadata stored in the element, and can be recovered by REFLECTION.

Exception

Exception refers to a method of default errors in C #. This is different from the error handling code in the VB because the exception cannot be ignored. When processing exceptions, the code area that may cause errors is included in the TRY area to place the error handling code in the CATCH area. This is the same as the VB's "On Error Goto" statement. Please see 2 examples below:

Try

{

INT J = 22/0;

}

Catch (Exception E)

{

Console.writeline ("exception" E.MESSAGE);

}

Please also pass the exception to the part of the call function:

Caller BEWARE: This method does not capture exceptions. This is the same as "On Error ResMe next" in VB.

Caller confuse: This method captures exception, processing exception, and re-throw exception. This is the same as "ERROR GOTO" and the error handling code in the error handling code.

Caller Inform: This method captures exception and wraps it in another exception with additional information.

Finally section:

This is where placing the clear code. For example, a file is turned off in an I / O operation. The code inside the Finally area must ensure that it is performed before exiting a function, regardless of whether the exception has been thrown. Please see the example below:

(Open the code (as the code of 'f' reference))

Finally

{

f.close ()

}

转载请注明原文地址:https://www.9cbs.com/read-3265.html

New Post(0)