铸造和解析的区别 [英] Difference between Casting and Parsing

查看:261
本文介绍了铸造和解析的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做一些code一段时间。现在我刚才使用的关键字作为,是没有真正理解它们。因此,这里是我的问题。

铸造和解析?之间的区别是什么

UserAdapter.GetIdAndUserTypeByEmailAndPassword(电子邮件,密码).Rows [0] [用户类型]为String - >是这样的铸造或解析

(字符串)UserAdapter.GetIdAndUserTypeByEmailAndPassword(电子邮件,密码).Rows [0] [用户类型] - >是这样的铸造或解析

UserAdapter.GetIdAndUserTypeByEmailAndPassword(电子邮件,密码).Rows [0] [用户类型。的ToString()
bewtween x.ToString有什么区别()(字符串)X

解决方案
  

铸造和解析?之间的区别是什么

这些都是无关的。

铸造被改变可变的类型。

解析是'检查'字符串,并指派其逻辑值的一些变量。

(加法:嗯,他们是相关的在某种意义上,因为从很远很远既可以起到'转换'的数据,但是数据确实是转换只在解析)

  

UserAdapter.GetIdAndUserTypeByEmailAndPassword(电子邮件,密码).Rows [0] [用户类型]为String

     

这是铸造或解析?

这是一种特殊的铸造如果类型是不可转换(看这不会失败的此处),但将让你

  

(字符串)UserAdapter.GetIdAndUserTypeByEmailAndPassword(电子邮件,密码).Rows [0] [用户类型]

     

这是铸造或解析?

这一次是铸造的,但如果EX pression的类型是不是会抛出异常字符串

  

bewtween x.ToString(差)和(串)x?

什么是

x.ToString()将尝试调用toString()对象x上。

(字符串)X 将尝试转换X要字符串,将失败如果x不是字符串。

I have been working on some code for a while. for now i have just used the keywords as-is without actually understanding them. So here is my question

What is the difference between Casting and Parsing?

UserAdapter.GetIdAndUserTypeByEmailAndPassword(Email, Password).Rows[0]["UserType"] as String--> is this Casting or parsing?

(String) UserAdapter.GetIdAndUserTypeByEmailAndPassword(Email, Password).Rows[0]["UserType"] -->is this Casting or parsing?

UserAdapter.GetIdAndUserTypeByEmailAndPassword(Email, Password).Rows[0]["UserType"].ToString()
What is the difference bewtween x.ToString() and (String) x?

解决方案

What is the difference between Casting and Parsing?

Those are unrelated.

Casting is changing the type of the variable.

Parsing is 'examining' the string and assigning its logical value to some variable.

(ADDITION: Well, they are related in a sense, because from far far away both can serve to 'convert' data, however, data is really converted ONLY in case of parsing)

UserAdapter.GetIdAndUserTypeByEmailAndPassword(Email, Password).Rows[0]["UserType"] as String

is this Casting or parsing?

This is special kind of casting that will not fail if types aren't convertible (look here), but will get you null.

(String) UserAdapter.GetIdAndUserTypeByEmailAndPassword(Email, Password).Rows[0]["UserType"]

is this Casting or parsing?

This again is casting, but will throw an exception if expression isn't of type string.

What is the difference bewtween x.ToString() and (String) x?

x.ToString() will try to call ToString() on the object x.

(String) x will try to cast x to string, and will fail if x isn't string.

这篇关于铸造和解析的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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