小编use*_*675的帖子

C#Threads -ThreadStart Delegate

执行以下代码会产生错误:ProcessPerson没有重载匹配ThreadStart.

public class Test
    {
        static void Main()
        {
            Person p = new Person();
            p.Id = "cs0001";
            p.Name = "William";
            Thread th = new Thread(new ThreadStart(ProcessPerson));
            th.Start(p);
        }

        static void ProcessPerson(Person p)
        {
              Console.WriteLine("Id :{0},Name :{1}", p.Id, p.Name);
        }

    }

    public class Person
    {

        public string Id
        {
            get;
            set;
        }

        public string Name
        {
            get;
            set;
        }


    }
Run Code Online (Sandbox Code Playgroud)

怎么解决?

c# multithreading

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

C#-Threading - 执行顺序

当我执行线程th1,th2和th3时,它们一个接一个地执行.如何更改我的代码,以便执行顺序不可预测.(不使用Random).

public class Test
{
    static void Main()
    {

        Person p = new Person();
        p.Id = "cs0001";
        p.Name = "William";

        Thread th1 = new Thread(()=>ProcessOne(p));
        th1.Name = "ThreadOne";
        th1.Start();

        Thread th2 = new Thread(()=>ProcessTwo(p));
        th2.Name = "ThreadTwo";
        th2.Start();

        Thread th3 = new Thread(()=> ProcessThree(p));
        th3.Name = "ThreadThree";
        th3.Start();

        Console.ReadKey(true);
    }

    static void ProcessOne(Person p)
    {
         Console.WriteLine("Thread {0} is executing", 
         Thread.CurrentThread.Name);
          Console.WriteLine("Id :{0},Name :{1}", p.Id, p.Name);
    }

    static void ProcessTwo(Person p)
    {
        Console.WriteLine("Thread {0} is executing",
        Thread.CurrentThread.Name);
        Console.WriteLine("Id :{0},Name :{1}", p.Id, …
Run Code Online (Sandbox Code Playgroud)

c# multithreading

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

C# lambda 表达式的转换

将以下内容转换为 lambda 表达式的方法是什么?

ThreadPool.QueueUserWorkItem(delegate
     {
        Console.WriteLine("Current Thread Id is {0}:",
         Thread.CurrentThread.ManagedThreadId);
        Console.WriteLine("I will be used as Callback");
      }
    );
Run Code Online (Sandbox Code Playgroud)

c# lambda

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

C#线程 - 中断

通常我们会中断一个处于"W​​aitSleepJoin"状态或"Running"状态的线程吗?

c# multithreading

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

返回随机字母表的扩展方法

如何开发一个可以从字母表(a,b,.... z)返回随机字符(单个字符)的扩展方法.

public static char RandomLetter(this char randomchar)
{

}
Run Code Online (Sandbox Code Playgroud)

c# extension-methods

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

Linq使用Aggregate()作为List

来自数据

OrderID     OrderAmt   OrderDate                                              
----------- ---------- --------------------
1           10.50      2003-10-11 08:00:00
2           11.50      2003-10-11 10:00:00
3           1.25       2003-10-11 12:00:00
4           100.57     2003-10-12 09:00:00
5           19.99      2003-10-12 11:00:00
6           47.14      2003-10-13 10:00:00
7           10.08      2003-10-13 12:00:00
8           7.50       2003-10-13 19:00:00
9           9.50       2003-10-13 21:00:00
Run Code Online (Sandbox Code Playgroud)

我想显示以下运行总计

OrderId     OrderDate            OrderAmt   Running Total                        
----------- -------------------- ---------- ------------- 
1           2003-10-11 08:00:00  10.50      10.50
2           2003-10-11 10:00:00  11.50      22.00
3           2003-10-11 12:00:00  1.25       23.25
4           2003-10-12 09:00:00  100.57     123.82
5           2003-10-12 11:00:00  19.99      143.81
6           2003-10-13 …
Run Code Online (Sandbox Code Playgroud)

c# linq

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

C#在扩展方法中指定orderby

如何在扩展方法中指定降序

var qry=from p in context.Persons 
                   orderby p.salary descending select p;
Run Code Online (Sandbox Code Playgroud)

扩展方法

var qry=context.Persons.OrderBy(c=>c.salary);
Run Code Online (Sandbox Code Playgroud)

c# linq

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

C# - 多线程 - 共享数据

线程是否可以在同一进程中共享数据(全局变量).

c# multithreading

0
推荐指数
1
解决办法
6947
查看次数

C#非元音词

我想要一个需要返回非元音词的扩展方法.我设计了

 public static IEnumerable<T> NonVowelWords<T>(this IEnumerable<T> word)
    {
        return word.Any(w => w.Contains("aeiou"));
    }
Run Code Online (Sandbox Code Playgroud)

我收到错误,因为"T"不包含extanesion方法"Contains".

c# extension-methods

0
推荐指数
1
解决办法
390
查看次数

C#以另一种方式对数字进行分组

在分组数字时,我使用

   string[] numbers = 
   { "123", "34555", "91882", "100", "7823", "1111", "76551" };

    var query = from digits in numbers
                group digits by digits.Length into ByDigit
                select
                new { digit = ByDigit, length = ByDigit.Key };
Run Code Online (Sandbox Code Playgroud)

当我想使用

var query = numbers.GroupBy() ( 我不知道如何命名,是否扩展链接?)

这是怎么做的?

c# linq

0
推荐指数
1
解决办法
160
查看次数

C# - 使用Aggregate()运行总计

这个问题是在面试时提出来的.我需要运行总计(仅使用Aggregate())

从数组

(即)

int[] array={10,20,30};

Expected output

10
30
60
Run Code Online (Sandbox Code Playgroud)

当我使用Aggregate时(我应用了一些最糟糕的逻辑)

array.Aggregate((a, b) => { Console.WriteLine(a + b); return (a + b); });
Run Code Online (Sandbox Code Playgroud)

1)It prints 30,60,对我来说没有使用return(a + b).

2)为了打印10,我必须通过添加元素零(即){0,10,20,30}来修改数组.

有什么整洁的工作可以把它变成现实吗?

c# extension-methods

0
推荐指数
1
解决办法
1579
查看次数

C#-LINQ-扩展方法

什么是以下LINQ的扩展方法等效?

var qry = from a in context.A_Collections
          from b in context.B_Collections
          where a.PK == b.PK
          select 
        new {
              A_key = a.PK, 
              A_Value = a.Value,
              B_Key = b.PK,
              B_value = b.value
            };
Run Code Online (Sandbox Code Playgroud)

我的意思是

(不完全的)

var query = context.A_Collections.
                Where(
                      a => a.PK == context.B_Collections.Select(b => b.PK)).
                    Select(
                            x => new { 
                                      A_key = a.Pk,
                                      A_Value = a.Value,
                                      B_Key = b.PK,
                                      B_value = b.value
                                     }
                           );
Run Code Online (Sandbox Code Playgroud)

c# linq

0
推荐指数
1
解决办法
259
查看次数

标签 统计

c# ×12

linq ×4

multithreading ×4

extension-methods ×3

lambda ×1