相关疑难解决方法(0)

将IEnumerable <char>转换为字符串的最佳方法?

为什么不能使用流利的语言string

例如:

var x = "asdf1234";
var y = new string(x.TakeWhile(char.IsLetter).ToArray());
Run Code Online (Sandbox Code Playgroud)

是不是有更好的转换IEnumerable<char>方式string

这是我做的一个测试:

class Program
{
  static string input = "asdf1234";
  static void Main()
  {
    Console.WriteLine("1000 times:");
    RunTest(1000, input);
    Console.WriteLine("10000 times:");
    RunTest(10000,input);
    Console.WriteLine("100000 times:");
    RunTest(100000, input);
    Console.WriteLine("100000 times:");
    RunTest(100000, "ffff57467");


    Console.ReadKey();

  }

  static void RunTest( int times, string input)
  {

    Stopwatch sw = new Stopwatch();

    sw.Start();
    for (int i = 0; i < times; i++)
    {
      string output = new string(input.TakeWhile(char.IsLetter).ToArray());
    }
    sw.Stop();
    var …
Run Code Online (Sandbox Code Playgroud)

.net regex performance performance-testing

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

打印阵列和任何类型列表的常用方法

每当我调试一段涉及数组或int,double,string等列表的代码时,我更喜欢有时打印它们.我为此做的是为不同类型编写重载的printArray/printList方法.

例如

我可以使用这3种方法来打印各种类型的数组

public void printArray(int[] a);

public void printArray(float[] b);

public void printArray(String[] s);
Run Code Online (Sandbox Code Playgroud)

虽然这对我有用,但我仍然想知道是否可以使用通用方法打印任何类型的数组/列表.这也可以扩展到对象的数组/列表.

c# generics debugging

12
推荐指数
2
解决办法
4万
查看次数

将List元素转换为String

在C#中将Int32列表转换为带有','之类的分隔符的字符串的最佳方法是什么?

c# list typeconverter

3
推荐指数
1
解决办法
855
查看次数