English 中文(简体)
系统。 努力是一种类别,但为什么我们不用新关键词立即使用?
原标题:System.String is a class type, but why we can use it without instantiate it with New keyword?

我对扼杀阶级有问题。 <代码>System.String是一种类别,但为什么我们可以使用,而不必随便使用New?

例如:

Dim CommandLineParameters As String = Microsoft.VisualBasic.Interaction.Command

没有任何新的关键词

最佳回答

页: 1

Dim s As String = "hello"

你们只是指定一个参考资料。 在幕后,汇编者生成密码,以瞬息万计标的<代码>hello>。 这种即时情况可能发生在派任之前很久,但详细情况是另一个例子。

简言之,上述法律没有立即提出反对。

同样,在你的例子中:

Dim CommandLineParameters As String = Microsoft.VisualBasic.Interaction.Command

没有任何物体被当场。 发生这种情况的是,对现有物体的提及被复制。

问题回答

是的,汇编者有一些捷径,让你在没有明确创建的情况下使用插座。

当你使用字面直观时,甚至在你使用时,它就没有产生,相反,在申请开始时,所有字面直线都是制造的,因此,你只复制了已经存在的说明。

你的榜样类似,你没有创造新的影响力,你只是复制了已经存在的说明。

你可以在不立即的情况下真正使用这一工具(下文将写一些警告)。 你可以:

A. 拷贝string reference to another string 参考

B) Add a string to a Nothing value. This has been added to simplify the using of strings. See f或 example C#: Why is adding null to a string legal? but it should be the same f或 VB.NET .

BUT

C) In VB.NET there is a big difference with C#: "internal" VB.NET functions consider Nothing to be equivalent of "". So Len(Nothing) = 0 and UCase(Nothing) = "". Methods of the string class will still throw an exception if used on Nothing (from String Manipulation and Nothing = String.Empty (Why are these equal?))

I ll add that string literals (f或 example "Foo") are pre-built during the loading of the assembly where they are defined. So if you do

Dim aString As String = "A String"

what you are doing is copying the reference of the string object containing "A String" to aString.

你可以。

char[] chars = {  w ,  o ,  r ,  d  };
string string1 = new string(chars);

string my string = "test";

that instantiates as new string with the value "test" What you are talking about is accessing Static Type members, such as String.Format or String.Join.





相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签