Share via


What is the equivalent of #include(in c++) in c#

Question

Saturday, January 31, 2009 8:15 PM

 Hi, can anybody tell me what the equivalent of #include is in c#?

All replies (3)

Saturday, January 31, 2009 9:34 PM ✅Answered | 1 vote

You have to add a Reference to the assembly (right click on the Reference folder on your project) , and then on your source code use the following:

1 using YourAssemblyName; 

Hope that helps.

RMedeiros


Saturday, January 31, 2009 11:19 PM ✅Answered

developer555 said:

 Hi, can anybody tell me what the equivalent of #include is in c#?

The concept of "include" files does not exist in C#.  A similar, but altogether different, functionality is achieved through the use of the "using" keyword. 

The C# compiler does not make as many passes through the code as what is done with C++.  You do not need to declare something in a file before you use it either, which was the pont of "#include".  This means the compiler does not care in what order stuff is written in the file, or in which order the files are processed.  Makes for tidier looking files.Mark the best replies as answers. "Fooling computers since 1971."


Sunday, February 1, 2009 10:04 PM ✅Answered

Hi, thanks for the replies. I have found the problem. I am using ASP.NET with c# and you can create 2 types of projects, a web application and a website. I am using the website option where I just could not get the compliler to recognise classes in other files. I have just tried a web application project and indeed the compiler has a path to classes in other files and there is no problem. I have found the problem, in the website option, you have to put all your code files in a folder called App_Code and then the compiler recognises classes in other files! I don't know what the designers of ASP.NET were thinking of when they did that!

cheers bye