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

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

内容简介:你确定你使用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


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

查看所有标签

猜你喜欢:

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

Algorithms to Live By

Algorithms to Live By

Brian Christian、Tom Griffiths / Henry Holt and Co. / 2016-4-19 / USD 30.00

A fascinating exploration of how insights from computer algorithms can be applied to our everyday lives, helping to solve common decision-making problems and illuminate the workings of the human mind ......一起来看看 《Algorithms to Live By》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

html转js在线工具
html转js在线工具

html转js在线工具