Is there any way to import classes and other files in c# like “include” in PHP ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no
includein C#. The closest you can get is creating classes that reside in namespaces, then generate ausingfor that namespace.For example, say you create a class in a separate file of your project and assign it to a namespace:
Now, in your main project, you can reference that namespace in two ways. Let’s assume your main project files look something like this:
Now, to put our
HelloWorldclass into the above code, we can either reference it directly, or add a using to the top of the page. For fully referenced method, substitute the comment above for:Or, we can add
using ProjectNamespace.SecondNamespaceto the top of the file, then just reference the class directly.