小编Sum*_*jee的帖子

构造函数中的枚举 - 如何?

我对此练习有一个问题:定义一个代表圆圈的类.保持pi值的常量定义类,以及在readonly中保持圆的颜色定义的变量.可能的颜色在枚举中定义.变量定义类以保持圆的半径和用于计算对象的周长和面积的函数.这就是我所做的:

    class Circle
{
    public const double PI = 3.14;
    public readonly enum color { Black, Yellow, Blue, Green };
    int radius;
    public Circle(string Color,int radius)
    {
        this.radius = radius;
    }
}
Run Code Online (Sandbox Code Playgroud)

我不知道如何将枚举选择放在构造函数中.谢谢你的帮助.

c# enums

9
推荐指数
2
解决办法
3万
查看次数

如何在C#中复制文件

我想在C#中将文件从A复制到B. 我怎么做?

.net c# file

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

计算列表中的重复数字

我有一个清单:

int list = { 1,1,2,3,4,4,5,7,7,7,10};
Run Code Online (Sandbox Code Playgroud)

现在我需要制作一个计算双数的程序.当前面的数字相同时,数字是两倍.我希望你明白.因此1是双倍,4是双打,我们在7,7,7中得到2双.

c# list

8
推荐指数
3
解决办法
2621
查看次数

如何在字典中找到最小键

我声明字典如下:

private Dictionary<int, touchInformation> touchDictionary = new Dictionary<int, touchInformation>();
Run Code Online (Sandbox Code Playgroud)

我使用如下:

touchDictionary[touchID] = touchObject;

因此,touchDictionary将保留来自touchID的密钥.现在,我尝试使用字典找到最小密钥,但我不知道该怎么做.有什么建议吗?

请注意,C.Porawat

c# dictionary

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

尾部递归优化发生在visual studio 10 x64调试但不在发布中?

最初我在x86模式下遇到了stackoverflow异常.我注意到x64会优化尾递归,所以我切换到x64编译.并且它在调试模式下优雅地运行.但是当我尝试运行发布代码时...它再次抛出stackoverflow ..任何可能的原因?

c# visual-studio-2010

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

将List <Enum>转换为List <string>

我有一个枚举值列表:

public static readonly List<NotifyBy> SupportedNotificationMethods = new List<NotifyBy> {
   NotifyBy.Email, NotifyBy.HandHold };
Run Code Online (Sandbox Code Playgroud)

我想将其输出为逗号分隔列表.(EG:"Email,Handhold")

这样做最干净的方法是什么?

c# asp.net-mvc list

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

C#,旋转2D数组

我已经看过关于旋转2D阵列的其他帖子,但它并不是我想要的.我想要这样的东西

 int[,] original= new int[4,2]
       {
           {1,2},
           {5,6},
           {9,10},
           {13,14}
       };
Run Code Online (Sandbox Code Playgroud)

我想把它变成这样,rotateArray = {{1,5,9,13},{2,6,10,14}}; 我想按列进行一些分析,而不是按行进行分析.

这有效,但有更简单的方法吗?

 private static int[,] RotateArray(int[,] myArray)
  {
        int org_rows = myArray.GetLength(0);
        int org_cols = myArray.GetLength(1);

        int[,] myRotate = new int[org_cols, org_rows];

        for (int i = 0; i < org_rows; i++)
        {
            for(int j = 0; j < org_cols; j++)
            {
                myRotate[j, i] = myArray[i, j];
            }
        }

        return myRotate;
    }
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法来迭代c#中的列?

c# arrays

7
推荐指数
1
解决办法
1536
查看次数

List <T>的动态类型?

我有一个方法返回DataSet表的List

public static List<string> GetListFromDataTable(DataSet dataSet, string tableName, string rowName)
    {
        int count = dataSet.Tables[tableName].Rows.Count;
        List<string> values = new List<string>();

        // Loop through the table and row and add them into the array
        for (int i = 0; i < count; i++)
        {
            values.Add(dataSet.Tables[tableName].Rows[i][rowName].ToString());
        }
        return values;
    }
Run Code Online (Sandbox Code Playgroud)

有没有办法可以动态设置列表的数据类型,并且这个方法适合所有数据类型,所以我可以在调用此方法时指定它应该是List<int> List<string>或者List<AnythingILike>

另外,在声明方法时返回类型是什么?

先谢谢,布雷特

c# list dynamic

7
推荐指数
1
解决办法
3176
查看次数

Count()(linq扩展名)和List <T> .Count之间有区别吗?

List<string> list = new List<string>() {"a", "b", "c"};
IEnumerable<string> enumerable = list;

int c1 = list.Count;
int c2 = list.Count();
int c3 = enumerable.Count();
Run Code Online (Sandbox Code Playgroud)

最后3个陈述之间在性能和实施方面是否存在差异?将list.Count()表现更差或相同list.Count,如果引用类型IEnumerable<string>是否重要?

c# list

7
推荐指数
1
解决办法
1671
查看次数

C# - 编译器错误 - 将int []赋给object []

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            object[] obj = new object[3];
            obj[0] = new object();
            obj[1] = "some string";
            obj[2] = 10;

            string[] strings = new string[] { "one", "two", "three" };
            obj = strings; //---> No Error here, Why ?

            int[] ints = new int[] { 1, 2, 3 };
            obj = ints; /*-> Compiler error - Cannot implicitly convert type 'int[]' to 'object[]', Why ?*/ 
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我在执行上述步骤时遇到编译器错误.但是,在上一步中,没有错误.有人能解释一下这种行为吗?我正在使用VS 2010.

编辑 - 为了完整性,再次,这将无法编译 …

c# compiler-errors

7
推荐指数
1
解决办法
1858
查看次数