C#字符串和字符串.为什么Visual Studio对它们进行不同的处理?

栏目: 编程工具 · 发布时间: 7年前

内容简介:你确定你使用String的例子实际上是编译的吗?小写字符串是一个等效于使用System.String的关键字;由于您的示例不导入System命名空间,我预计会导致编译错误,这可能导致项目属性无法识别您的Main方法.添加使用系统;指示代码文件或明确使用System.String而不是String来使编译器知道类型.

如果我创建一个普通的控制台应用程序与正常的主入口点如下

using System;

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

然后选择它在视觉工作室一切都很好..

C#字符串和字符串.为什么Visual Studio对它们进行不同的处理?

但是,如果我写下如下代码:

using System;

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

那么一切都不是很好….

C#字符串和字符串.为什么Visual Studio对它们进行不同的处理?

有人知道为什么不拿起字符串[]但是对字符串[]感到满意吗?

编辑:从评论中提取,它似乎是Visual Studio 2012和2013中的一个错误.据推测,它也在早期版本中出现,但似乎已在VS2015中得到纠正.这不是一个问题本身,并且代码仍然使用string []或String []编译和执行,我有兴趣知道VS中的错误的原因.我想象的属性编辑器窗口不是使用系统; ?

你确定你使用String的例子实际上是编译的吗?

小写字符串是一个等效于使用System.String的关键字;由于您的示例不导入System命名空间,我预计会导致编译错误,这可能导致项目属性无法识别您的Main方法.

添加使用系统;指示代码文件或明确使用System.String而不是String来使编译器知道类型.

http://stackoverflow.com/questions/32520812/c-sharp-string-and-string-why-is-visual-studio-treating-them-differently


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Tagging

Tagging

Gene Smith / New Riders / 2007-12-27 / GBP 28.99

Tagging is fast becoming one of the primary ways people organize and manage digital information. Tagging complements traditional organizational tools like folders and search on users desktops as well ......一起来看看 《Tagging》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

SHA 加密
SHA 加密

SHA 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具