c# - (type)objectname.var 中的 (type) 是什么

标签 c# casting

我正在阅读一本关于 C# 的书,遇到了一些我似乎无法查找的东西,因为我不知道它叫什么,或者试图通过描述搜索一些东西。

有人可以向我解释发生了什么,或者在对象引用之前出现的 (type) 背后的含义,如 (int)objectname.variablename?

这对我来说就像是转换。

编辑: 由于当我只是猜测并且需要更多代码时,你们中的大多数人都不再引用“我的”类型转换,所以我包括了我正在审查的代码,这些代码带来了这个问题。我在质疑 (int)numericupDown1.Value 中的 (int);

private void numericUpDown1_ValueChanged(object sender, EventArgs e) 
{
    dinnerParty.NumberOfPeople = (int)numericUpDown1.Value;
    DisplayDinnerPartyCost();
}

最佳答案

它正在转换,它试图在运行时将变量名转换为类型(type)

关于c# - (type)objectname.var 中的 (type) 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3166349/

相关文章:

c# - WCF自带的EndpointBehavior读取客户端Session

c# - wpf 中的可排序 WrapPanel

c# - 将 Canvas 转换为 WPF 中的按钮

c# - 抛出类型为 'System.OutOfMemoryException' 的异常。使用 IDataReader 时的 C#

c# - 通用接口(interface)的运行时转换

Java 类/对象转换何时适用

c - 如何从指针读取 64 位到 8 位值

c# - Azure Data Lake Store - 从文件读取时出错

C# 继承 : casting of parent object to child

java - 使用表达语言进行转换