需要C#代码的说明 [英] Need with explanation for C# Code

查看:58
本文介绍了需要C#代码的说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提供2个班级:

Given 2 classes:

public class SomePublisher
{
public event EventHandler SomeEvent;
}
 
public class SomeSubscriber
{
public static int Count;
 
public SomeSubscriber(SomePublisher publisher)
{
publisher.SomeEvent += new EventHandler(publisher_SomeEvent);
}
 
~SomeSubscriber()
{
SomeSubscriber.Count++;
}
 
private void publisher_SomeEvent(object sender, EventArgs e)
{
// TODO: something
}
}


执行以下操作后将显示什么以及原因:


What would be printed after executing the following and why:

SomePublisher publisher = new SomePublisher();
 
for (int i = 0; i < 10; i++)
{
SomeSubscriber subscriber = new SomeSubscriber(publisher);
subscriber = null;
}
 
GC.Collect();
GC.WaitForPendingFinalizers();
 
Console.WriteLine(SomeSubscriber.Count.ToString());

推荐答案

C#编译器可以帮助您解决这一问题.只需下载visual studio(用作编译器的简易包装)并进行以下操作即可:
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express [ ^ ]

祝你好运!
The c# compiler can help you out with that. Just download visual studio (to use as an easy wrapper for the compiler) and give it a go:
http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express[^]

Good luck!


这篇关于需要C#代码的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆