View Full Version : Question reguarding C# [CODE]

12-23-2011, 09:13 PM
I was just wondering what would be the consequence for not using "System" keyword in the line:


I know it still works without the "System" part, but is there any drawbacks?

12-24-2011, 12:52 AM
Alykins can confirm; I don't believe it will cause any errors. I believe that C# does an implicit static import of the System package by default. You can do the same in Java as well to use just out.println, but its not done by default.
So I'd say its more the style. I write a lot of PHP code, and because of this I *ALWAYS* use this. in both C# and Java even when its not really necessary.

12-24-2011, 02:50 AM
usually the only time i use a line like that is... well actually never- my "style" (as Fou-Lu alluded to the subject of doing this) is to always have it @ the top so

using System;
using System.IO;
using System.Text;

etc... if I find a namespace not referenced I add it to the top as is my style (and I assume probably a MS best practice)

to my knowledge no difference other than the fact that you have to keep doing it over and over and over again if you do not reference it so for example

System.Net.IPEndPoint var = new System.Net.IPEndPoint(new System.Net.IPAddress(132456), 9105);
IPAddress demo;

that line IPAddress demo would fail out because the namespace System.Net was not referenced.

in short there is most likely a reason I have never seen anyone do it like that routinely ;)

12-24-2011, 03:19 AM
so if you had added "using System.Net"; then it would work either way, correct?

also did you mean most people write it out explicitly or do they jsut reference the needed namespaces and use the abbreviated versions?