C # exception, type conversion, array, etc ..

Source: Internet
Author: User

In general, if we know the possible exception types in the program, capture them as much as possible and pop up a prompt to the client. exceptions that we don't know are captured and then write log records. The business logic can be ignored.

1. nullreferenceexception null reference exception

2. stackoverflowexception Stack Overflow

3. timeoutexception the exception that is thrown when the specified Timeout time has been reached

4. argumentexception an exception that is thrown when one of the parameters provided to the method is invalid (in some control events, exceptions with invalid parameter types may occur)

5. threadabortexception exceptions thrown when calling the abort Method

6. indexoutofexception: this class is used to handle exceptions caused by the subscript exceeding the array length.

7. ioexception: this class is used to handle exceptions caused by file input/output operations.

8. arithmeticexception: this class is used to handle arithmetic-related exceptions.

9. dividebyzeroexception: indicates the exception caused by trying to divide the integer by zero in decimal operation.

 

Ii. type conversion

IS rules are as follows:

• Check the compatibility of object types and return results, true or false;

• No exception is thrown;

• If the object is null, the return value is always false.

The as rules are as follows:

• Check the compatibility of object types and return results. If not, null is returned;

• No exception is thrown;

• If the result is null, an nullreferenceexception is thrown when the type conversion is forced.

Code:

If (O is)

{A = (a) O ;}

A A = (a) O;

If (! = NULL ){}

 

3. What are the similarities and differences between interfaces and abstract classes?

Similarities

• They cannot be directly instantiated. They can all be inherited to implement their abstract methods.

• It is the technical basis for abstract programming and implements many design modes.

Differences

• Interfaces support multi-inheritance; abstract classes cannot implement multi-inheritance.

• Interfaces can only define abstract rules. abstract classes can define rules and provide implemented members.

• An interface is a set of behavioral norms; an abstract class is an incomplete class that focuses on the concept of a family.

• Interfaces can be used to support callback. abstract classes cannot implement callback because inheritance is not supported.

• Interfaces only contain signatures for methods, attributes, indexers, and events, but cannot define fields or methods that contain implementations. abstract classes can define fields, attributes, and methods that have implementations.

• The interface can act on the Value Type and reference type. abstract classes can only act on the reference type. For example, struct can inherit interfaces rather than classes.

3. Differences between copying and cloning arrays, deep copying, and shallow copying

Shallow copy: if the Members in the array are of the value type (such as int, float, double, byte), the values are completely copied to the target array, if it is a reference type (for example, user-defined type, or class type in the class library: arraylist), it refers to copying the reference to the target array.

Deep copy: Completely creates new objects. create a new object for all objects in the original array. modifications to the new array do not affect the values in the original array or the copyto () and clone () objects are both shortest copies, which is beyond doubt.

How to implement deep copy?

. Net Library does not seem to provide a deep COPY method, to achieve deep copy, you need to traverse the array, copy each object in the original array, layers of depth, until the object in this object ...... The object in is of the value type.

Because only the value type is completely copied, modifying one value does not affect the other value.

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.