What is C# equivalent of c++'s #include ? How do I reuse .cs files? What is a assembly reference and how do I make one?
7 replies to this topic
#1
Posted 16 September 2010 - 01:44 PM
|
|
|
#2
Posted 16 September 2010 - 06:57 PM
1) There is no include statement in C#. Like C++; C# goes by namespaces. Well, there is an <include>, but it was meant for accessing XML comments in another file.
2) I assume you mean a reference to a COM/DLL assembly, you only need to include the assembly within your project,
2) I assume you mean a reference to a COM/DLL assembly, you only need to include the assembly within your project,
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 17 September 2010 - 10:12 AM
And if I have a file and I want to use the code of such file in another?
What I mean is: C++ has files .h to reuse code, what does C# has ?
What I mean is: C++ has files .h to reuse code, what does C# has ?
#4
Posted 17 September 2010 - 10:37 AM
You don't need to add any reference to other files. If both files are in the same namespace (and are compiled together), the compiler will find any needed declaration, whatever the file. If files are in different namespaces, then you must add a reference in one file to the namespace of the other file using the directive 'using <namespace>', but you never add references to specific files.
#5
Posted 17 September 2010 - 11:39 AM
dbug said:
You don't need to add any reference to other files. If both files are in the same namespace (and are compiled together), the compiler will find any needed declaration, whatever the file. If files are in different namespaces, then you must add a reference in one file to the namespace of the other file using the directive 'using <namespace>', but you never add references to specific files.
#6
Posted 19 September 2010 - 01:23 AM
Keyword USING is equivalent for #Include that is used to import external classes and libraries in C++
In C# you can either create a object for the class you defined in the external file or Create a Assembly(.dll) file and then add it to the [Bin] folder of your application and reference it by dragging it to the using statements in your editor [Visual Studio 2008/2010 ]
In C# you can either create a object for the class you defined in the external file or Create a Assembly(.dll) file and then add it to the [Bin] folder of your application and reference it by dragging it to the using statements in your editor [Visual Studio 2008/2010 ]
#7
Posted 19 September 2010 - 11:41 AM
gokuajmes said:
Keyword USING is equivalent for #Include that is used to import external classes and libraries in C++
Including a reference to the DLL (right click on References, select Add in the VS IDE) is how you import external classes.
Refer to Using Directive for more information about using.
#8
Posted 20 September 2010 - 12:36 AM
well i was being a bit general out there, When someone asks he wants to learn C#, you should always explain it from his point of view and not scare him with intricacies of C# [and make him cry mommy :D ] . That is how I teach people new to technology but it differs from people to people
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









