小编Nik*_*las的帖子

有什么机会获得Guid.NewGuid()重复?

可能重复:
GUID在100%的时间内是唯一的吗?
简单证明GUID不是唯一的

在MSDN中,您可以阅读:

新Guid的值全部为零或等于任何其他Guid的可能性非常低.

假设您有一个每秒都会创建一个文件的方法,并且您使用该方法 Guid.NewGuid()的文件名,是否可以获得相同的Guid呢?或者本地计算机会以某种方式跟踪?机会有多低?

c# guid

33
推荐指数
3
解决办法
6万
查看次数

什么是"根基参考"?

Eric Lippert 引用(C#中的安全不在C++中,指针/参考的简单返回,答案3).

另请注意,它不是对Person对象的任何引用使其保持活动状态.参考必须扎根.你可以有两个Person对象相互引用但是无法访问; 每个人都有参考的事实并不能让他们活着; 其中一个参考文献必须扎根.

我不明白,有人可以解释什么是根源参考?

c# clr reference

16
推荐指数
2
解决办法
7388
查看次数

Process.MainModule - >"访问被拒绝"

我想以不同的方式处理这个问题,即.确定我是否有权访问.

是否可以查看您是否可以访问主模块?

foreach (Process p in Process.GetProcesses())
        {
            try
            {
                //This throws error for some processes.
                if (p.MainModule.FileName.ToLower().EndsWith(ExeName, StringComparison.CurrentCultureIgnoreCase))
            {
                 //Do some stuff
            }

            }
            catch (Exception)
            {  
                //Acess denied 
            }
        }
Run Code Online (Sandbox Code Playgroud)

c# process

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

赋值运算符在返回语句中的含义是什么,例如return t = ...?

我有疑问,在我的代码示例中返回赋值表达式意味着什么?我有一个枚举,我已经覆盖了++:运算符.因此,在我的简短示例中可以在ligth之间切换 - 但是代码中有一部分我不明白.代码编译并正常工作.

码:

enum Traficlight
{green, yellow, red };

Traficlight& operator++(Traficlight& t)
{
    switch (t)
    {
    case green: return t = Traficlight::yellow; //Here <--
    case yellow: return t = Traficlight::red; //Here <--
    case red: return t = Traficlight::green; //Here <--
    default:
        break;
    }
}

int main()
{


    Traficlight Trafic = Traficlight::green;
    Trafic++;

    if (Trafic == Traficlight::yellow)
    {
        cout << "Light is Yellow" << endl;
    }

    string in;

    cin >> in;

}
Run Code Online (Sandbox Code Playgroud)

"返回t = Traficlight :: yellow"是什么意思,为什么我只能返回"Traficlight :: yellow".

c++ enums return

7
推荐指数
2
解决办法
1196
查看次数

平等运营商 - 总是左联合的,是否重要?

在c#语言规范中,可以找到"除了赋值运算符,所有二元运算符都是左关联的"

但它会为平等运营商带来不同吗?==和!=?

说:bool X,Y,Z ......

return x == Y == z ...依此类推?

即使x,y,z ...的顺序在return语句中有所不同,结果总是相同的,总是返回相同的值吗?(如果x,y,z的init值明显相同)

(x == y)== z等于x ==(Y == z)和(x!= y)== z等于x!=(Y == z)

对?

c# operators

6
推荐指数
3
解决办法
708
查看次数

为什么本地捕获的计时器不会超出范围?

可能重复:
定时器,事件和垃圾收集:我错过了什么?

private void TrayForm_Load(object sender, EventArgs e)
{
    System.Timers.Timer HideMeTimer = new System.Timers.Timer(2500);
    HideMeTimer.Elapsed +=  
        delegate(object sender2, System.Timers.ElapsedEventArgs e2)
        {
            this.Invoke(new Action(somestuff));
        };
        HideMeTimer.Start();
        GC.Collect();
}
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我编译器将如何翻译吗?或者很好地解释为什么定时器在加载事件之后继续滴答作响.

(当最后一个引用消失时,不是规则,变量,GC有时会杀死对象!)

c# garbage-collection timer capture

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

多继承的模糊解决方法?

我有一个叫做动物的基类,一个继承自Animal的狗和一只猫.还有一个名为dogcat的多继承类,它继承自dog和cat,在Animal中我有一个名为sleep的方法.当我想从dogcat使用那个方法时,我得到错误"DogCat :: sleep"是模棱两可的,我确实理解了这个问题,但我在一本书中读到,当你将睡眠宣布为虚拟时它应该是可能的 - 但它不起作用.

这不可能是书错了还是有任何解决方法?

class Animal
{
public:
    Animal(){}

    virtual void sleep()
    {
        cout << "zzzzzzzzz" << endl;
    }
    virtual void eat() = 0;

};

class Dog: public Animal
{
protected:
    Dog(){}

    virtual void eat() override
    {
        cout << "eats dogfood" << endl;
    } 
};

class Cat :public Animal
{
public:
    Cat(){}
    virtual void eat() override
    {
        cout << "eats catfood" << endl;
    }
};

class DogCat : public Dog, public Cat
{
public:
    DogCat(){}
    using Dog::eat;

}; …
Run Code Online (Sandbox Code Playgroud)

c++ multiple-inheritance

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

是否有可能获得自己的进程名称?

我想替换cMyProcessName(在我的例子中)编程,我不想使用sting常量!

这是代码:

private const string cMyProcessName = "MyProcessName";

if (GetProcessCount(cMyProcessName) > 1)
{
    System.Threading.Thread.Sleep(2000); //Give it some time (if just restarted)
    //**************************************************************//
    if (GetProcessCount(cMyProcessName) > 1)
    {
        MessageBox.Show("MyProcessName is already running. Exiting.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }
    //**************************************************************//
}

public static int GetProcessCount(string processName)
{
    Process[] ps = Process.GetProcessesByName(processName);

    return ps.Length;
}
Run Code Online (Sandbox Code Playgroud)

c# process

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

是什么让委托多目标对象留在范围内?

什么t是根本参考(留在范围内)?(t是用户定义的类)

我在IL间谍中看到它,它不是一个常见的捕获变量!

Action runs = null;
while (dummy <= tod.Value.Date)
{
   var t = new Task(dummy, _interval);
   runs += t.Run;

   dummy = dummy.AddDays(1);
}
GC.Collect();
((Action)(() => { runs(); })).BeginInvoke(Result, null);
Run Code Online (Sandbox Code Playgroud)

谁可以给我解释一下这个?t(任务)类如何保持在范围内,是什么使它成为根,我猜它的运行委托,但如何?

.net c# delegates garbage-collection

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

是一个IQueryable列表不是通过引用?(linq to sql)

如果我们先拿一个简单的例子来看看我的观点(只是一个普通的清单)

    private void button1_Click(object sender, EventArgs e)
    {
        List<string> Olle = new List<string>();

        Olle.Add("Niklas");
        Olle.Add("Peter");
        Olle.Add("Tobias");

        RemoveFirst(Olle);

        MessageBox.Show(Olle.Count().ToString()); 

    }
    private void RemoveFirst(List<string> O)
    {
        O.Remove(O.First());  
    }
Run Code Online (Sandbox Code Playgroud)

消息框将显示2,因为列表是参考!

我期望IQueryable或IEnumerable圈套列表的相同行为(Linq to Sql),但令我惊讶的是它变成了一个值变量,有人可以向我解释这个吗?即.传递一个方法后回来,方法是过滤列表!根据以下示例:

    private void foo(int therecord)
    {
      var FooList = DataContext.MyTable.Where
                    (l => l.ID == therecord).OrderBy(l => l.FirstName).ToList();

       //Lets say the result is 15 records. 
        MessageBox.Show(FooList.Count().ToString());

       //filter method
        RemoveDoubletItems(FooList);


       //Still 15 records - why? It should pass by refernce right? 
       //and show 14 - But its not !    

        MessageBox.Show(FooList.Count().ToString());

    }

    private void …
Run Code Online (Sandbox Code Playgroud)

c# linq

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