What is the difference between reference and using?

Source: Internet
Author: User

The purpose of adding a reference to a project is to introduce an assembly.
What is the concept of assembly?
An assembly is a DLL, which is a prerequisite for calling a class.
An Assembly contains one or more namespaces.
For example
The namespace System. Data comes from the file System. Data. DLL.
The namespace System. Data. SqlClient is also from System. Data. DLL.
This means that once you add a reference to the System. Data Assembly file (whether you add a DLL from the GAC or directly add it to the Project)
You can use the various types of System. Data and System. Data. SqlClient

Why using?
To put it simply, you don't even need to write a using. You can use a fully qualified name for all types you need.

What is a fully qualified name?
For example, the DataSet class DataSet: System. Data. DataSet is its fully qualified name.
For example, the database connection class SqlConnection: System. Data. SqlClient. SqlConnection is its fully qualified name.

The advantage of using is that you do not have to write fully qualified names everywhere, which will make the Code look too lengthy.
Speaking of this, do you understand the role of using? In fact, it plays a short role.
The real reference work is done at the beginning, and using is just to make your subsequent coding work simple and easy.

As for the using,
In the end, it is because the class you are using has an incomplete Class Name (that is, a non-fully qualified name ),
The system does not know where the class comes from,
The system will find the source of this class in all using,
If you do not have using, you cannot find it.

The last example is as follows:

You need to define a dataset,

Method 1
Using System. Data;
Then
DataSet mySet = new DataSet ();

Method 2:
No using
Direct
System. Data. DataSet mySet = new System. Data. DataSet ();

Of course, both methods require that you add references to System. Data to the project.
Both methods are feasible, but do you think the first method is more concise?

 

From http://topic.csdn.net/u/20070202/13/8e124bb9-3e46-4f5e-ab4e-3c7aeeb367e0.html? 2058447783

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.