Alex Rivera | Logout

(Question on best practice) Why is "using System.Text" there by default?

Asked 2011-06-07T02:34:00.033
14

Every time I creat a class, I see using System.Text that is added (amongst other using) by default. Every time I remove it after a while because it is unused according to ReSharper.

Am I missing a best practice? Do you use that namespace often? In which situation?

There has to be a reason why this namespace is referenced by default.

Thanks!

Edit
Report

3 Answers

13

The System.Text namespace contains classes, abstract base classes and helper classes. Say for example if you wanted to take advantage of the StringBuilder, Decoder, Encoder, etc....

The classes above, plays a significant role in most cases in .net. But it is not necessary for it to be there in your code. It only applies as to when you needed it. The important thing is to know when you will need the namespace.

It is added in visual studio by default for the convenience of the developers. Same with the System.Linq namespace, not all of the time you will be using it but for your convenience it is already added assuming that you would be using it and that would be up to you to remove it which is by case to case basis.

Sometimes it would be a lot easier to delete it if it is not needed than to figure out the namespace and type when you need it :)

More info regarding System.Text

answered 2011-06-07T03:16:06.103
2

If you don't like it you can always create your own item templates. See http://msdn.microsoft.com/en-us/library/tsyyf0yh(v=VS.80).aspx

answered 2011-06-07T02:52:30.623
1

If you are not using it, don't include the namespace. It is just automatically included because it is one of the more commonly used namespaces. I generally use it if I want to use regular expressions or string manipulation methods. But if you remove it and there are no compiler errors, it is safe to leave it out.

answered 2011-06-07T02:37:31.233

Your Answer