5

Coming from a VB background and being forced to learn C# I have hit the first hurdle.

In VB i could put all the namespaces I wanted available across the entire app in the web.config file and it would be available in each code behind file without me having to add import statements.

<namespaces>
<clear/>
<add namespace="System"/>
<add namespace="System.Collections"/>
<add namespace="System.Collections.Generic"/>

It seems Visual Studio can't do this with C# and I have to add using statements all over the place.

Please tell me I'm missing something obvious and there is a way to get this done.

3
  • 4
    Forced huh? You'll look back at this moment in the future with fond regard. Commented Jan 13, 2009 at 7:30
  • I hope so. Right now I'm about to throw something through a window :) Commented Jan 13, 2009 at 7:40
  • 3
    I grudgingly concede that you may have been right Jon. Commented Feb 8, 2011 at 13:09

2 Answers 2

8

For C#, the namespaces entered in the web.config will be recognized in .aspx files, but not codebehind. I don't think it will take you long to adjust (Ctrl-. will let you quickly add a namespace when you type a class name that doesn't have the namespace referenced).

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

Comments

3

This ability is only for VB.NET, the C# project does not support it :/. But, you can create a template for new source code file ( C# Wizard Templates in Visual Studio .NET , How To: Edit Visual Studio Templates ) and change default namespaces as you wish.

Comments

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.