小编use*_*606的帖子

使用C#中的Regex解析带有日期和时间戳的文本

我有以下字符串 -

Default (45-889) %69 (Test Case)-1/24/2012 12:16:01 AM-1/24/2012 12:16:11 AM-1/24/2012 12:16:24 AM-1/24/2012 12:18:03 AM-1/24/2012 12:19:15 AM-1/24/2012 12:19:52 AM-1/24/2012 12:19:59 AM-1/24/2012 12:20:03 AM
Run Code Online (Sandbox Code Playgroud)

我想在C#中使用Regex将上面的字符串拆分成一个数组.

拆分后,我的数组应如下所示:

  • Default (45-889) %69 (Test Case)
  • 1/24/2012 12:16:01 AM
  • 1/24/2012 12:16:11 AM

如何使用Regex将字符串拆分为C#中的字符串数组.

c# regex

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

多个计时器访问单个对象中的字典对象

我有一个单例对象,并在其中定义了一个字典.

public class MyClass 
{
    public static readonly MyClass Instance = new MyClass();

    private MyClass
    {}

    public Dictionary<int, int> MyDictionary = new Dictionary<int, int>();
}
Run Code Online (Sandbox Code Playgroud)

现在,我有两个System.Timers.Timer对象更新MyDictionary.

System.Timers.Timer timer1 = new System.Timers.Timer(5);
timer1.AutoReset = false;
timer1.Elapsed += new System.Timers.ElapsedEventHandler(MyTimer1Handler);
timer1.Enabled = true;
timer1.Start();

System.Timers.Timer timer2 = new System.Timers.Timer(5);
timer2.AutoReset = false;
timer2.Elapsed += new System.Timers.ElapsedEventHandler(MyTimer2Handler);
timer2.Enabled = true;
timer2.Start();

private void MyTimer1Handler(object sender, ElapsedEventArgs e)
{
     MyClass.Instance.MyDictonary[1] = 100;
}

private void MyTimer1Handler(object sender, ElapsedEventArgs e)
{
     MyClass.Instance.MyDictonary[2] = 100;
} …
Run Code Online (Sandbox Code Playgroud)

c# multithreading timer

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

标签 统计

c# ×2

multithreading ×1

regex ×1

timer ×1