字符串s ="prakash"之间的差异;和字符串s = new string();在C尖锐 [英] difference between string s="prakash"; and string s=new string(); in c sharp

查看:134
本文介绍了字符串s ="prakash"之间的差异;和字符串s = new string();在C尖锐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

字符串s ="prakash"之间的差异;和字符串s = new string();在C Sharp

[edit]已删除代码块,将我的内容视为纯文本..."选项已禁用-OriginalGriff [/edit]

difference between string s="prakash"; and string s=new string(); in c sharp

[edit]Code block removed, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]

推荐答案

一个区别是第二个甚至没有编译,因为字符串没有没有参数的构造函数.

如果可以的话,我想明显的区别是,第一个将创建一个字符串,内容将为"prakash",第二个将导致一个空字符串...
One difference is that the second on doesn''t even compile since string doesn''t have a constructor without parameters.

If it would work then I guess the obvious difference is that the first one will create a string and the contents will be "prakash" and the second one would result to an empty string...


没有真正的区别,只是构造器版本不会编译(不存在不带参数的字符串构造器).

当您输入
There is no real difference, except that the constructor version will not compile (there is not string constructor which takes no parameters).

When you type
string s = "prakash";

在C#中,编译器将其解释为隐式

in C#, the compiler interprets it as an implicit

string s = new string(new char[] {'p', 'r', 'a', 'k', 'a', 's', 'h'});


这篇关于字符串s ="prakash"之间的差异;和字符串s = new string();在C尖锐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆