Use of keyword “Using” in C# interface

When I’m using C# to write some code and I define an interface using Visual Studio 2010, it always includes a number of “using” statements (as shown in the example)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestEngine.TestNameSpace
{
    interface ITest1
    {
        bool testMethod(int xyz);
    }
} 

I wonder what these are for and if they are really necessary. Can I leave these out? Are they only necessary when I’m using those parts in my interface description?

7

Visual Studio doesn’t know what code you intend to write so includes the most common namespaces for you by default in the “new class” template. This is done so you don’t have to resolve all the references for every single line of new code you write.

Once you have written your basic code you can safely remove the ones you don’t need. You will have to add any back that you subsequently need to reference in any subsequent code you write.

If you right click and select Organize Usings > Remove and Sort it will delete any that are unused. There are also extensions that will remove and sort the namespaces automatically on saving each file.

5

Yes you can remove any using directive that is not being used.These directives are automatically added by visual studio since they are the most commonly used ones and if for instance you are not going to use linq in the interface then you can remove the directive

 System.Linq;

The same holds true for other directives as well.Also it is a good practice in my opinion to move the using directives inside namespaces.

2

These default using statements are part of your default template when creating interfaces. You can always edit the template to have them removed. See this question for more details.

4

In short, they are called namespaces. Namespaces are also used to reference some library classes within your code. There is also a recommended guidelines on how to use namespaces in .NET

In most cases, you may simple remove them if not used. The following two namespaces are potential candidates to to be removed.

using System.Collections.Generic;
using System.Linq;

Visual Studio will complain and NOT compile the code, once some framework/library classes have been used without declaring their namespaces. Thus, namespace play roll of structuring your code as well as easing the references between the project classes, interfaces, constructs, etc.

using in C# used for many ways.. as word keyword using means using.. on start when we used using system; that means there is a DLL of name System in which all main functions are stored and we use it to short our code…

system.WriteLine("Andy");

but when we use system above then we can write it as

WriteLine("Andy");

more over in SQLserver when we use using connection it means after we use data from database by using command connection will itself close. it is very useful for a coder who wants to save its time

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật