15

If I create a normal Console App with a normal Main entry point as follows

using System;

namespace ConsoleApp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // do stuff
        }
    }
}

then select it in visual studio everything is fine..

enter image description here

However, if I write the code as follows...

using System;

namespace ConsoleApp
{
    public class Program
    {
        public static void Main(String[] args)
        {
            // note the capital S in String
        }
    }
}

then everything is not fine....

enter image description here

Does anyone know why is it not picking up the String[] but happy with the string[] please ?

edit: Extracting from comments, it appears to be a bug in Visual Studio 2012 and 2013. Presumably it's also present in earlier editions but appears to have been rectified in VS2015. It's not a problem per se, and as noted the code still compiles and executes with either string[] or String[] I'd be interested to know the cause of the bug in VS though. I'd imagine the property editor window isn't Using System; ?

SkeetJon
  • 1,471
  • 1
  • 18
  • 39
  • 3
    I can reproduce this in VS 2013, but not in VS 2015 – M4N Sep 11 '15 at 10:12
  • 3
    Just ignore. Your code will compile and work fine. Seems like a glitch in project property editor. – Nikhil Vartak Sep 11 '15 at 10:13
  • Can you elaborate why this would ever cause any trouble? It seems they have fixed it in VS 2015 though – huysentruitw Sep 11 '15 at 10:14
  • 1
    It is a (very weird) bug present in VS 2012 too. – varocarbas Sep 11 '15 at 10:14
  • 2
    So does your code have `using System;` at the top and compile, or not? If it does, please include that in your question, as otherwise it's a big red herring. Also, does this actually cause issues? If you try to run the project, what happens? – Jon Skeet Sep 11 '15 at 10:15
  • 1
    You said in a separate comment "It's reproducible with or without `using System`" - those are very different situations, given that it won't *compile* without `using System`. – Jon Skeet Sep 11 '15 at 10:16
  • sorry yes, using System is definitely there in both string[] and String[] examples – SkeetJon Sep 11 '15 at 10:20
  • 5
    Haha. Finally a difference between string and its alias – M.kazem Akhgary Sep 11 '15 at 10:21
  • So... It's obviously still a valid entry point. Are we talking about a suspected bug in Visual Studios? I tried this change on my project and I couldn't reproduce. – Nathan Cooper Sep 11 '15 at 10:21
  • I cannot remember where, but I have read that `String` is meant to be used for methods and `string` is used for string storage. But don't quote me on that lol – Makar Emelyanov Sep 11 '15 at 10:29
  • Side note: I find this hilariously funny that SkeetJon was edited by Jon Skeet. I feel like SkeetJon is a fanboy. – Skintkingle Sep 11 '15 at 10:37
  • http://thoughtcatalog.com/justin-hook/2012/09/12-reasons-you-should-never-meet-your-hero/ – SkeetJon Sep 11 '15 at 10:42
  • 1
    Same bug (in VS2013) with cases like `Main(System.String[] args)` and `Main(global::System.String[] args)` and `Main(MyUsingAliasToSystemDotString[] args)` all of which are legal and compile without problem. – Jeppe Stig Nielsen Sep 11 '15 at 11:18

1 Answers1

4

Are you sure your example that uses String does actually compile?

Lowercase string is a keyword that is equivalent to using System.String; since your example doesn't import the System namespace, I expect it will cause compilation errors which might result in the project properties not being able to identify your Main method.

Add a using System; directive to the code file or explicitly use System.String instead of String to make the type known to the compiler.

waldrumpus
  • 2,460
  • 14
  • 39
  • It seems to work fine either way. But the behaviour showed in the picture (startup project recognised only with string) is actually happening (at least in VS 2012). – varocarbas Sep 11 '15 at 10:13
  • the example does import system. it compiles either way with string[] or String[]. edited question to show this – SkeetJon Sep 11 '15 at 10:13
  • @Heyyou Thanks, I tried adding explicit steps to fix the issue; of course this answer is no longer relevant. – waldrumpus Sep 11 '15 at 11:21