小编Rac*_*acs的帖子

我什么时候应该为 ApartmentState.STA 设置一个线程?

我很想知道 C# .net 中何时使用 STA/MTA?

using (ManualResetEventSlim mre = new ManualResetEventSlim(false)) 
{       
    Thread _STAThread = new Thread(new ThreadStart(() =>                 
        {
             globalComObject = new ComClass();                     
             mre.Set();                     
             try                     
             {                         
                  Thread.CurrentThread.Join();
             }
             catch (ThreadAbortException)                     
             { } 
         }));
     _STAThread.SetApartmentState(ApartmentState.STA);                    
     _STAThread.IsBackground = true;                 
     _STAThread.Start();                 
     mre.Wait(); 
} 
Run Code Online (Sandbox Code Playgroud)

.net c#

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

C#重载运算符==

//overloading operator ==
class Point
{
    private int m_X,int m_Y;

    public static operator == (Point p1 ,Point p2)
    {
        if(object.ReferenceEquals(p1,p2)
            return true;

        if((object)(p1) == null) || ((object)(p2) ==null)
            return false;

        return( (p1.x == p2.x) && (p1.x == p2.x));
    }

    //overloading the != operator
}
Run Code Online (Sandbox Code Playgroud)
  1. 是否有必要覆盖Equals功能
  2. 如果p1和p2没有被类型转换为对象,则抛出堆栈溢出异常为什么我们需要将Point对象强制转换为对象.

c#

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

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

标签 统计

.net ×2

c# ×2

debugging ×1