考虑以下代码:
int age = 25;
short newAge = 25;
Console.WriteLine(age == newAge); //true
Console.WriteLine(newAge.Equals(age)); //false
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
这两个int和short是原始类型,但有一个比较==返回true,并用比较Equals返回false.
为什么?
考虑以下代码:
static void Main(string[] args)
{
Get<Student>(new Student());
System.Console.Read();
}
public static void Get<T>(T person)
{
Console.WriteLine("Generic function");
}
public static void Get(Person person)
{
person.Show();
}
Run Code Online (Sandbox Code Playgroud)
这是我的人类:
class Person
{
public void Show()
{
Console.WriteLine("I am person");
}
}
class Student : Person
{
public new void Show()
{
Console.WriteLine("I am Student");
}
}
Run Code Online (Sandbox Code Playgroud)
我打电话Get给学生并通过该方法.就像这样:
Get<Student>(new Student());
Run Code Online (Sandbox Code Playgroud)
所以我明白了:Generic function但是我打电话的时候Get是这样的:
Get(new Student());
Run Code Online (Sandbox Code Playgroud)
我希望这Get(Person person)可以被调用Get<T>(T person).但是再次打电话:.为什么编译器有这种行为?
考虑以下代码:
var dropDown = sheet.DataValidations.AddListValidation(cells[2, colIndex, maxCol, colIndex].Address);
foreach (var bb in brokerBranchs)
{
dropDown.Formula.Values.Add(bb.Title);
}
Run Code Online (Sandbox Code Playgroud)
有25个dropDown项目一切正常,创建的excel文件工作正常但是当项目数超过29时,打开创建的文件显示以下错误:
打开损坏的结果文件会丢弃与所有列关联的所有下拉项.这个问题的可能解决方案是什么?任何帮助将不胜感激.