C# 代码里面的 IS AS 什么意思?

whoisyoung 2006-07-20 07:06:58
列如
if(objecta is objectb)
{
(objecta as objectb).function();
}

is as 身意思 有什么特别的用法吗 ?
...全文
241 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Knight94 2006-07-20
  • 打赏
  • 举报
回复
参看
http://blog.csdn.net/Knight94/archive/2006/06/12/791850.aspx
viena 2006-07-20
  • 打赏
  • 举报
回复
as 运算符用于将一个值显式地转换(使用引用转换或装箱转换)为一个给定的引用类型。与强制转换表达式(第 7.6.6 节)不同,as 运算符从不引发异常。它采用的是:如果指定的转换不可能实施,则运算结果为 null。

在 e as T 形式的运算中,e 必须是一个表达式,T 必须是一个引用类型。该运算的结果属于类型 T,且总是可归类为值类别。运算按下面这样计算:

如果 e 的编译时类型与 T 相同,则结果就是 e 的值。
否则,如果存在从 e 的编译时类型到 T 的隐式引用转换(第 6.1.4 节)或装箱转换(第 6.1.5 节),则执行该转换,且该转换的结果就是运算结果。
否则,如果存在从 e 的编译时类型到 T 的显式引用转换(第 6.2.3 节),则执行动态类型检查:
如果 e 的值为 null,则结果为具有编译时类型 T 的值 null。
否则,假设 R 为 e 引用的实例的运行时类型。如果 R 和 T 的类型相同,或者如果 R 为引用类型且存在从 R 到 T 的隐式引用转换,或者如果 R 为值类型且 T 是由 R 实现的一个接口类型,则结果为由 e 给定的具有编译时类型 T 的引用。
否则,结果为具有编译时类型 T 的值 null。
否则,指定的转换根本不可能实现,且发生编译时错误。
注意,as 运算符只执行引用转换和装箱转换。不可能使用 as 运算符执行其他转换(如用户定义的转换),应改为使用强制转换表达式来执行这些转换。
viena 2006-07-20
  • 打赏
  • 举报
回复
is请参见
C# 关键字 | typeof | as | 运算符关键字
is 运算符用于检查对象的运行时类型是否与给定类型兼容。is 运算符用在以下形式的表达式中:

expression is type
其中:

expression
引用类型的表达式。
type
类型。
备注
如果满足下列两个条件,则 is 表达式计算为 true 值:

expression 非 null。
expression 可以被转换为 type。也就是说,将完成形式 (type)(expression) 的转换表达式而不引发异常。有关更多信息,请参见 7.6.6 强制转换表达式。
如果已知 expression is type 表达式总是为 true 或总是为 false,则会发出编译时警告。

不能重载 is 运算符。

请注意,is 运算符只考虑引用转换、装箱转换和取消装箱转换。is 运算符不考虑其他转换(如用户定义的转换)。
支持向量机源码,可在 www.csie.ntu.edu.tw/~cjlin/libsvm/ 下载到最新版本,该版本是 2013年4月更新的,3.17 版。压缩包里面有源代码和文档。以下摘自前述网站: Introduction LIBSVM is an integrated software for support vector classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and distribution estimation (one-class SVM). It supports multi-class classification. Since version 2.8, it implements an SMO-type algorithm proposed in this paper: R.-E. Fan, P.-H. Chen, and C.-J. Lin. Working set selection using second order information for training SVM. Journal of Machine Learning Research 6, 1889-1918, 2005. You can also find a pseudo code there. (how to cite LIBSVM) Our goal is to help users from other fields to easily use SVM as a tool. LIBSVM provides a simple interface where users can easily link it with their own programs. Main features of LIBSVM include Different SVM formulations Efficient multi-class classification Cross validation for model selection Probability estimates Various kernels (including precomputed kernel matrix) Weighted SVM for unbalanced data Both C++ and Java sources GUI demonstrating SVM classification and regression Python, R, MATLAB, Perl, Ruby, Weka, Common LISP, CLISP, Haskell, OCaml, LabVIEW, and PHP interfaces. C# .NET code and CUDA extension is available. It's also included in some data mining environments: RapidMiner, PCP, and LIONsolver. Automatic model selection which can generate contour of cross valiation accuracy.

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧