C # review 7,

Source: Internet
Author: User

C # review 7,

C # review 7

June 22, 2016

Main Exception & Namespaces & Assemblies Exception & namespace & assembly

1. try statement

Example

FileStream s = null;try {s = new FileStream(curName, FileMode.Open);...} catch (FileNotFoundException e) {Console.WriteLine("file {0} not found", e.FileName);} catch (IOException) {Console.WriteLine("some IO exception occurred");} catch {Console.WriteLine("some unknown error occurred");} finally {if (s != null) s.Close();}

Note:

The execution of catch statements is sequential;

The finally statement is always executed;

The exception parameter name can be omitted in the capture clause;

Exception classes are inherited from System. Exception;

2. System. Exception

Attribute:

E. Message the error message as a string;
Set by new Exception (msg );

E. StackTrace trace of the method call stack as a string

E. Source the assembly that threw the exception

E. TargetSite the method that threw the exception

Method:

E. ToString () returns the name of the exception and the StackTrace

3. Throwing an Exception throws an Exception

Illegal operation:

Divide by 0;

The following table is out of bounds;

Call empty reference;

Throw statement:

throw new MyException(10);class MyException : ApplicationException {public int errorCode;public MyException(int x) { errorCode = x; }}

4. exception class

5. Search Path of the catch statement

6. C # comparison between exceptions and Java exceptions

7. Exceptions in delegation and exceptions in multicast Delegation

Exception Handling in delegation:

8. C # Namespaces VS Java Packages

9. Assemblies

Assembly: the smallest unit of version control; the smallest unit of dynamic loading;

Including manifest, codes + Metadata

9. Namespaces VS Assemblies

Namespaces: constructed during compilation; control visibility;

Assemblies: runtime structure; controls dynamic loading and version control; may contain types from different Namespaces;

10. Compiler Options command selection during compilation

11. Versioning of Assemblies Version Control

The version number is stored in the Assembly. The version number is checked every time the Assembly is loaded.

12. Private and Public Assemblies

Private Assembly:

It can only be used by one application;

Is used by only one application

Save it in the application directory;

Resides in the application directory

No strong naming;

Does not have a "strong name"

Unable to sign;

Cannot be signed

Public Assembly (or shared assembly ):

Can be used by all applications;

Can be used by all applications

Saved in global Assembly

Resides in the Global Assembly Cache (GAC)

A strong name is required;

Must have a "strong name"

Signatures are supported;

Can be signed

GAC stores Assemblies with the same name but has different versions;

GAC can hold assemblies with the same name but with different version numbers

13. Strong Names & Signing Assemblies & Checking the Signature

Strong naming includes four parts:

Assembly name

Assembly version;

Cultural attributes of Assembly;

The public key of Assembly.

(1) Generate a key file with sn.exe (Strong Name Tool)

(2) Sign the assembly with the AssemblyKeyFile attribute

It is not usable even if the class modified by internal is named in different assemblies under the same namespace.

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.