Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question reguarding C# [CODE]

    I was just wondering what would be the consequence for not using "System" keyword in the line:

    System.Console.WriteLine();
    or
    System.Console.ReadLine();

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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #3
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,742
    Thanks
    41
    Thanked 191 Times in 190 Posts
    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
    Code:
    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
    Code:
    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

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • Users who have thanked alykins for this post:

    jameswray50 (12-24-2011)

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •