这段代码是什么意思? Name =(string)item.Element(" Name"),? [英] What does this code line means ? Name= (string)item.Element("Name"), ?

查看:108
本文介绍了这段代码是什么意思? Name =(string)item.Element(" Name"),?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码行的含义是什么? Name =(string)item.Element(Name)?



是否意味着声明字符串类型的变量?

那么什么是下面代码之间的区别?

string Name = item.Element(Name);



以下是什么意思?



i =(int)cellFormat.FontId.Value; ???是这样吗

int i = cellFormat.FontId.Value?

What does this code line means ? Name= (string)item.Element("Name") ?

is it means declaring variable of type string ?
Then what is the difference between below code?
string Name = item.Element("Name");

what does below means ?

i = (int)cellFormat.FontId.Value; ??? is this same as
int i =cellFormat.FontId.Value ?

推荐答案

Name =(string)item.Element(Name )不声明任何变量 - 它使用已经声明的名称并将值放入其中。



究竟什么 item.Element(Name)部分是打开的:不知道什么类型 item 它可以是什么,但最有可能的是它是一个泛型方法,从某个形式的商店返回对象,使用名称作为索引来准确找到你的项目想要取。 (string)部分将该对象强制转换为字符串(如果可以的话,它会失败并抛出异常,如果它不能),这样编译器就会很开心将值转换为名为的字符串变量名称



Name= (string)item.Element("Name")Doesn't declare any variables - it use the already declared Name and puts a value into it.

Exactly what the item.Element("Name") part does is open: without knowing what type item is it could be anything, but the most likely is that it's a generic method that returns an object from a store of some form, using "Name" as the index to locate exactly what item you want to fetch. The (string) part casts that object to a string (if it can, it will fail and throw and exception if it can't) so that the compiler will be happy stroign the value into a string variable called Name

string Name = item.Element("Name");

声明 Name 变量,如果Element方法没有返回字符串类型,可能会产生编译错误。



你的其他两行做的非常类似,但这次把值转换为整数而不是字符串。



这是基本的东西:如果你不太了解这一点,你真的需要回到你的笔记中并从一开始就查看语言。

Does declare the Name variable, and will probably give a compilation error if the Element method does not return a string type.

Your other two lines do very similar things, but this time casting the value to a integer instead of a string.

This is basic stuff: you really need to go back in your notes and review the language from the beginning if you don't understand this too well.


引用:

这段代码是什么意思? Name =(string)item.Element(Name)?

What does this code line means ? Name= (string)item.Element("Name") ?

分配给( string )变量名称 item.Element(Name)的值,已铸造(已嵌入)到字符串。< br $>






Assign to the (string) variable Name the value of item.Element("Name"), casted (that is coherced) to string.



引用:

是否意味着声明字符串类型的变量?

is it means declaring variable of type string ?

No.







No.



Quote:

那么下面代码有什么区别?

string Name = item.Element(Name) ;

Then what is the difference between below code?
string Name = item.Element("Name");

在前一段代码中有一个显式的强制转换(当 item.Element(Name) type 不需要时 string ,例如 object ),上面一行中缺少。







In the former piece of code there is an explicit cast (required when item.Element("Name") type is not string, e.g. is object) which is missing in the above line.



Quote:

i =(int)cellFormat .FontId.Value; ???是否与

int i = cellFormat.FontId.Value?

i = (int)cellFormat.FontId.Value; ??? is this same as
int i =cellFormat.FontId.Value ?

相同。您可以对这些行应用相同的注意事项。

You may apply the same considerations to these lines.


这篇关于这段代码是什么意思? Name =(string)item.Element(&quot; Name&quot;),?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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