C # basic series-Assembly 1

Source: Internet
Author: User
Tags visual studio 2010

The accessible attributes of the class include public, private, protect, innertal, and protect internal. Internal is accessible only in files of the same assembly, and internal types or members. The following example uses this to continue the assembly.

namespace AssemblyLibrary{    internal class InternalClass    {        public int ID { get; set; }    }    public class PulClass    {        public int ID { get; set; }        public InternalClass Inter { get; set; }    }}

Are you sure this compilation works? Obviously, if you have a good foundation, you can see that there is a syntax error without using the compiler. As a class attribute, the access of the attribute cannot be higher than that of the type.

 

 

In vs, we can see the Assembly name. If we change it to the same Assembly name, then internal can access it?

Then I modified the Assembly name of the test console to assemblylibrary, and the result was very frustrating. If you say that the class library and console are not of the same type, well, let's do another experiment. Let's create a new class library named assemblylibrary2. Assembly: assemblylibrary, default namespace: assemblylibrary. Now we have the same set of programs and namespaces for both class libraries. Let's start the following experiment.

namespace AssemblyLibrary{    public class Show    {        public int ID { get; set; }    }}

Project: In assemblylibrary, we modify the code

namespace AssemblyLibrary{    internal class InternalClass    {        public int ID { get; set; }    }    public class PulClass    {        public int ID { get; set; }        internal InternalClass Inter { get; set; }        public Show SHOW { get; set; }    }}

 

The current project directory is like this. assemblylibrary references assemblylibrary2.

Press F6 to compile and OK. No problem.

Let's use ilspy to see how the compiled DLL works?

 

It is amazing that there is only one DLL in it. Let's skip this step and decompile it.

In ilspy, we can see the DLL assembly information // assemblylibrary, version = 1.0.0.0, culture = neutral, publickeytoken = NULL

using System;namespace AssemblyLibrary{    public class PulClass    {        public int ID        {            get;            set;        }        internal InternalClass Inter        {            get;            set;        }        public Show SHOW        {            get;            set;        }    }}

OK. It is exactly the same as the code we wrote, but clicking show won't jump to the relevant class. Click internalclass to complete the content.

 

However, here we can see the show information, which is really interesting.

 

Okay. Now we can reload consoltest and modify the code.

namespace AssemblyLibrary{    class Program    {        static void Main(string[] args)        {            PulClass pu = new PulClass();            pu.ID = 1;            pu.SHOW = null;            Console.Read();        }    }}

The result is terrible. Although the PU. Show smart prompt can be displayed, an error is returned:

Error 5: the current language does not support "assemblylibrary. pulclass. Show" D: \ Documents ents \ Visual Studio 2010 \ projects \ consoltest \ Program. CS 15 16 consoltest

In this case, // PU. Show = NULL; what will happen? No error is returned, but four more warnings are given. Let's ignore him first. F5: Let's see what's happening.

System. typeloadexception error thrown

Failed to load type assemblylibrary. pulclass from assembly "assemblylibrary, version = 1.0.0.0, culture = neutral, publickeytoken = NULL ".

 

Well, this is a frustrating experiment. We found that we didn't understand the assembly.

Without knowing it, I found that this page already contains a lot of content. I think it takes more than one page to elaborate on this Assembly.

 

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.