gpt4 book ai didi

c# - 类型转换操作中的不同行为?

转载 作者:太空宇宙 更新时间:2023-11-03 21:21:42 24 4
gpt4 key购买 nike

<分区>

谁能给我解释一下,为什么在下面的两个转换场景中,转换变量的行为不同?虽然第一个变量(双初始值)在第一个示例代码中保留了它的初始值,但“sender”对象根据它被转换成的新变量改变了它的内容属性值?

第一个示例:

double initialValue = 5;

int secValue = (int)initial;

secValue = 10;

Console.WriteLine(initial); // initial value is still 5.

第二个示例:

private void Button_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
btn.Content = "Clicked"; // "sender" objects content property is also set to "Clicked".
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com