C#:铸造'0'为int [英] C#: Casting '0' to int
本文介绍了C#:铸造'0'为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看到这样的代码:
private readonly object[] m_Values = { (int)0, (int)0 };
什么是投0为int的想法?是不是通过INT默认?
What's the idea to cast 0 to int? Isn't it int by 'default' ?
推荐答案
这是没有必要的。我认为程序员得到了前咬伤。 ?我会后它作为一个益智游戏,这将超载在这个程序中调用
It is not necessary. I'd assume the programmer got bitten before. I'll post it as a puzzler, which overload will be called in this program?
using System;
class Program {
static void Main(string[] args) {
Foo.Bar(0);
Console.ReadLine();
}
}
class Foo {
public static void Bar(byte arg) { Console.WriteLine("byte overload"); }
public static void Bar(short arg) { Console.WriteLine("short overload"); }
public static void Bar(long arg) { Console.WriteLine("long overload"); }
}
这篇关于C#:铸造'0'为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文