小编Moh*_*ani的帖子

对于C#中的原语,==和Equals()之间有什么区别?

考虑以下代码:

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)

这两个intshort是原始类型,但有一个比较==返回true,并用比较Equals返回false.

为什么?

c# compare

179
推荐指数
7
解决办法
2万
查看次数

在c#中调用泛型方法

考虑以下代码:

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).但是再次打电话:.为什么编译器有这种行为?

c#

8
推荐指数
1
解决办法
450
查看次数

Epplus excel文件中的下拉项限制数

考虑以下代码:

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时,打开创建的文件显示以下错误: 在此输入图像描述 打开损坏的结果文件会丢弃与所有列关联的所有下拉项.这个问题的可能解决方案是什么?任何帮助将不胜感激.

c# excel export-to-excel epplus

5
推荐指数
1
解决办法
4286
查看次数

标签 统计

c# ×3

compare ×1

epplus ×1

excel ×1

export-to-excel ×1