简体   繁体   English

StringBuilder 命名空间,c#,Visual Studio 2010

[英]StringBuilder namespace, c#, visual studio 2010

What namespace does StringBuilder belong to? StringBuilder属于什么命名空间?

I typed:我输入:

using System.Text.StringBuilder;

But the intellisense, won't let me type StringBuilder .但是智能感知不会让我输入StringBuilder

Its very easy to determine in which namespace .NET class lives.很容易确定 .NET class 生活在哪个命名空间中。 you have two ways:你有两种方法:

  1. Find interesting class in MSDN and in Inheritance Hierarchy section you can see FULL class name.在 MSDN 和Inheritance Hierarchy部分中找到有趣的 class,您可以看到完整的 class 名称。 Full class name means that before class name would be its namespace.完整的 class 名称意味着在 class 名称之前将是其命名空间。 For StringBuilder full class name would face as System.Text.StringBuilder .对于 StringBuilder 完整的 class 名称将面对System.Text.StringBuilder Just omit class name (StringBuilder) and you get namespace只需省略 class 名称(StringBuilder),你就会得到命名空间
  2. Open Object browser in VS and search for interesting class.在VS中打开Object浏览器,搜索感兴趣的class。 In results, click on the class and in detail view interesting information will appear:在结果中,单击 class 会出现详细查看有趣的信息:在此处输入图像描述

I always use second way, because its more easy for me.我总是使用第二种方式,因为它对我来说更容易。

using directives "import" namespaces, so it should read using System.Text; using指令“导入”命名空间,所以它应该using System.Text;

It's in the System.Text namespace.它位于 System.Text 命名空间中。

http://msdn.microsoft.com/en-us/library/2839d5h5(v=VS.100).aspx http://msdn.microsoft.com/en-us/library/2839d5h5(v=VS.100).aspx

If you're ever unsure what namespace something is in, type it into the editor (eg StringBuilder ) and hit Ctrl.如果您不确定某物在哪个名称空间中,请将其输入到编辑器(例如StringBuilder )并按Ctrl。 (control dot) to bring up the possible namespaces. (控制点)调出可能的命名空间。

VS2010 will then insert a using declaration into the file for you. VS2010 会为你在文件中插入一个 using 声明。

Remove the .StringBuilder in your using directive.删除 using 指令中的.StringBuilder StringBuilder is the class itsself. StringBuilder 本身就是 class。

The namespace is System.Text , not System.Text.StringBuilder命名空间是System.Text ,而不是 System.Text.StringBuilder

Alternatively you can just type StringBuilder , right click it, and choose "Resolve >".或者,您可以只键入StringBuilder ,右键单击它,然后选择“Resolve >”。 This way you can import the right namespace without knowing the name.这样您就可以在不知道名称的情况下导入正确的命名空间。 You'd have to type the class name correctly though.不过,您必须正确输入 class 名称。

If you have the.dll file added as a reference (and for something as basic as that, you have the reference), simply write StringBuilder (case-sensative) and hit Alt+Shift+F12 (or mouse over the small arrow near it) and you'll see a list of possible solutions, one of them will be to automatically add the correct using, which, in this case is:如果您添加了 .dll 文件作为参考(对于基本的东西,您有参考),只需编写 StringBuilder(区分大小写)并按 Alt+Shift+F12(或将鼠标悬停在它附近的小箭头上) 你会看到一个可能的解决方案列表,其中一个是自动添加正确的使用,在这种情况下是:

using System.Text

Namespace StringBuilder belong to - System.Text;命名空间 StringBuilder 属于 - System.Text;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM