2

I am use to VB.NET. The game source code I am learning from is written in C#. I find it annoying that I have to add using System.Diagnostics to the source code in order to type Debug.WriteLine.... I checked under project properties, but I cannot find the References tab that allows me to add namespaces to Imported Namespaces. Where do I find this in C#?

Also, why can't I do this in C#? Imports System.Math

4 Answers 4

3

Place the cursor over Debug in the source code, a red squiggle appears in the right bottom corner of the word, press Shift+Alt+F10 Enter - the using is automatically added.

Also, why can't I do this in C#? Imports x = System.Math

You can: using x = System.Math;

Sign up to request clarification or add additional context in comments.

3 Comments

I am sorry, I meant Imports = System.Math. I will change my question.
Shift+Alt+F10 is handy. Thank you very much.
A much better shortcut is CTRL+. which is easier on the fingers
3

I don't think you can have "hidden" namespaces in C# like you can in VB.NET (not sure).

As for the second part about System.Math, you can do the following at the top of each file.

using SM = System.Math;

SM.Abs(...);

3 Comments

I changed my question I meant Imports System.Math
@Fred F. : because c# does not support the Imports keyword. Also, System.Math is a class and not a namespace.
Yes, that is what the error message states, but it does not say why, and the help message for the error does not provide any information.
1

It is possible to modify Visual Studio's template for new C# classes. This is not exactly the same feature as in Visual Basic, but for any newly created class you can get the namespaces that you like.

It's a little more than just a few mouse clicks unfortunately, but you will find all the details described in Anson Horton's blog post:

Item templates - adding references by default

Note that this allows you not only to modify the default using directives but also to modify the assemblies that get referenced automatically when adding a new class.

As the blog post related to Visual Studio 2005, you probably need to adjust some paths, e.g. the class.zip file is located under C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033 in Visual Studio 2008.

Comments

0

In c# you should always explicitly specify namespaces you want to use or use a full name:

System.Diagnostics.Debug.WriteLine ( ... );

Also, there is a references tab under a solution view, you have to reference desired assemblies there, because many assemblies are not referenced by default.

4 Comments

It is such a pain-in-the-butt. It is frustrating when you cannot use intellisense to find what you need.
Darin Dimitrov specified in his answer how you can partially solve the problem. Unfortunately this can't be used for not-referenced assemblies.
Your answer reads as if you should not make use of using to import namespaces, which is a little confusing to me.
No, i in no way intended to sound like this, which part you think is confusing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.