c# - 为什么 int 和 string 情况下的结果不同?
问题描述
我正在学习 c#,但我无法理解为什么以下代码中的结果不同:
public class Thing
{
public object Data = default(object);
public string Process(object input)
{
if (Data == input)
{
return "Data and input are the same.";
}
else
{
return "Data and input are NOT the same.";
}
}
}
和里面的主要方法:
var t1 = new Thing();
t1.Data = 42;
Console.WriteLine($"Thing with an integer: {t1.Process(42)}");
var t2 = new Thing();
t2.Data = "apple";
Console.WriteLine($"Thing with a string: {t2.Process("apple")}");
输出是:
Thing with an integer: Data and input are NOT the same.
Thing with a string: Data and input are the same.
解决方案
推荐阅读
- php - laravel 使用不同的 php 版本
- c# - 如果应用程序已最小化、在后台或用户空闲,如何停止 WPF 应用程序?
- ruby - Squib DataFrame 上的 If 语句
- javascript - Discord.js v12,潜在的拆分错误,在命令后读取 args 并执行它
- amazon-dynamodb - Dynamoose 中的虚拟字段
- git - 尝试在 Ubuntu 服务器上进行 git pull/push 时出错
- postgresql - 我如何在 gorm 1.20.0 中关闭数据库实例
- python - 使用 Python 将 for 循环结果添加到 Excel 电子表格
- bash - 使用 bash 变量时出现“意外的 $end”
- google-maps - 谷歌地图没有使用谷歌数据工作室填充谷歌表格中的所有邮政编码