Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# String and string. Why is Visual Studio treating them differently?

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; ?

like image 578
SkeetJon Avatar asked Sep 11 '15 10:09

SkeetJon


1 Answers

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.

like image 144
waldrumpus Avatar answered Oct 03 '22 01:10

waldrumpus