Possible Duplicate: Any sense to set obj = null(Nothing) in Dispose()? I understand if this question is closed as a duplicate, but I'm having some trouble reconciling some posts on this topic. First a little background. I have a class Foo as follows public class Foo : IDisposable { private Dictionary<int, string> _reallyBigDictionary = new Dictionary<int, str
可能重复: 任何意义在Dispose()中设置obj = null(Nothing)? 我理解这个问题是否作为重复被关闭,但我在协调关于此主题的一些帖子时遇到了一些麻烦。 首先有一点背景。 我有一个类Foo如下 public class Foo : IDisposable { private Dictionary<int, string> _reallyBigDictionary = new Dictionary<int, string>(); public void Dispose() { _reallyBigDictionary =
After going through a lot of articles of Idisposable i got confused about it usage. All articles explain what is it and how to implement. I want to understand what we will miss if we don't have it. It is an interface with one method Dispose() in it. Let's take an example Often the use of dispose is shown as disposing a database connection. The code would be like Public class Test:I
在经历了很多Idisposable的文章后,我对它的使用感到困惑。 所有文章解释了它是什么以及如何实施。 我想知道如果我们没有它,我们会想念什么。 它是一个Dispose()方法的接口。 我们举一个例子通常,使用dispose显示为处理数据库连接。 代码会是这样的 Public class Test:Idisposable { public Test() { DatabaseConnection databaseConnection = new DatabaseConnection(); } public void Dispose() {
I know Dispose() is intended for unmanaged resource, and the resource should be disposed when it is no longer needed without waiting for the garbage collector to finalize the object. However, when disposing the object, it suppress finalization of the garbage collector (GC.SuppressFinalize(this); in the code below). This means that if the object includes managed resource, we will have to take c
我知道Dispose()用于非托管资源,并且在不等待垃圾收集器完成对象时不再需要该资源时应该处理该资源。 但是,在处理对象时,它会在下面的代码中抑制垃圾回收器的完成(GC.SuppressFinalize(this);)。 这意味着如果对象包含托管资源,我们也必须处理这个问题,因为垃圾收集器不会清理它。 在下面的示例代码(来自MSDN)中,“Component”是一个托管资源,我们称这个资源为dispose()(component.Dispose())。 我的问
I'm learning about Memory management in C# from the book "Professional C#" The presence of the garbage collector means that you will usually not worry about objects that you no longer need; you will simply allow all references to those objects to go out of scope and allow the garbage collector to free memory as required. However, the garbage collector does not know how to free u
我正在学习C#中的“Professional C#”中的内存管理 垃圾收集器的存在意味着你通常不会担心你不再需要的对象; 您只需简单地允许对这些对象的所有引用超出范围,并允许垃圾回收器根据需要释放内存。 但是,垃圾收集器不知道如何释放非托管资源(如文件句柄,网络连接和数据库连接)。 当托管类封装对非托管资源的直接或间接引用时,需要做出特别的规定,以确保在垃圾收集类的实例时释放非托管资源。 定义类时,可以使用两种
This is what I understand about IDisposable and finalizers from "CLR via C#", "Effective C#" and other resources: IDisposable is for cleaning up managed and unmanaged resources deterministically. Classes that are responsible for unmanaged resources (eg file handles) should implement IDisposable and provide a finalizer to guarantee that they are cleaned up even if the clien
这是我从“CLR via C#”,“Effective C#”和其他资源中了解IDisposable和终结器的内容: IDisposable用于确定性地清理托管和非托管资源。 负责非托管资源(例如文件句柄)的类应实现IDisposable,并提供终结器以确保即使客户端代码未在实例上调用Dispose(),也会清除它们。 只负责管理资源的类不应该实现一个终结器。 如果你有一个终结器,那么你必须实现IDisposable(这允许客户端代码做正确的事情并调用Dispose(),
What I want to do is something like this: I have enums with combined flagged values. public static class EnumExtension { public static bool IsSet<T>( this T input, T matchTo ) where T:enum //the constraint I want that doesn't exist in C#3 { return (input & matchTo) != 0; } } So then I could do: MyEnum tester = MyEnum.FlagA | MyEnum.FlagB if( tester.I
我想要做的是这样的:我已经枚举了带标记值的组合。 public static class EnumExtension { public static bool IsSet<T>( this T input, T matchTo ) where T:enum //the constraint I want that doesn't exist in C#3 { return (input & matchTo) != 0; } } 那么我可以这样做: MyEnum tester = MyEnum.FlagA | MyEnum.FlagB if( tester.IsSet( MyEnum.FlagA ) ) //act on f
I am converting a C# project into VB.net and need to understand C#'s Yield Break. I know there are already questions concerning Yield Break on Stack Overflow, but I feel these questions are a little different. 1.) When you Yield Break does the function that contains it return a value to the caller? If so, is it Null/Nothing, the default value for the type that the function is, or somethin
我正在将一个C#项目转换为VB.net,并且需要了解C#的Yield Break。 我知道已经有关于堆栈溢出Yield Break的问题,但我觉得这些问题有点不同。 1.)当你发生收益中断时,包含它的函数返回一个值给调用者? 如果是这样,它是空/无,该函数的类型的默认值,或其他? 2.)当您发生中断时,迭代器重新开始。 换句话说,下一次调用Iterator时,它会再次返回集合中的第一个项目吗? 3.)什么是最接近的vb.net相当于Yield Brea
I've spent a few months trying to grasp the concepts behind WCF and recently I've developed my first WCF service application. I've struggled quite a bit to understand all the settings in the config file. I am not convinced about the environment but it seems that you can do amazing stuff with it. The other day I've found out that Microsoft has come out with a new thing called
我花了几个月的时间来掌握WCF背后的概念,最近我开发了我的第一个WCF服务应用程序。 我努力了解配置文件中的所有设置。 我不相信环境,但你似乎可以用它做出惊人的东西。 有一天,我发现微软已经推出了一种名为ASP.NET Web API的新功能 。 对于我所能读的,这是一个RESTful框架 ,非常易于使用和实施。 现在,我想弄清楚2框架之间的主要区别是什么,如果我应该尝试使用新API转换旧的WCF服务应用程序。 请有人能帮我
C# 2008 I have been working on this for a while now, and I am still confused about some issues. My questions are below I know that you only need a finalizer if you are disposing of unmanaged resources. However, if you are using managed resources that make calls to unmanaged resources, would you still need to implement a finalizer? However, if you develop a class that doesn't use any u
C#2008 我一直在研究这个问题一段时间,而且我仍然对一些问题感到困惑。 我的问题如下 我知道如果你正在处理非托管资源,你只需要一个终结器。 但是,如果您使用调用非托管资源的托管资源,您是否仍需要实现终结器? 但是,如果您直接或间接开发一个不使用任何非托管资源的类,是否可以实现IDisposable以便您的类的客户端可以使用“使用语句”? 实施IDisposable只是为了让您的班级的客户可以使用using语句是否可以接受
I am writing the unit test and receive exception when trying to raise the event from abstract class mock. Here is the sample code: public abstract class AbstractBase : EntityObject {} [TestMethod] public void MyTest() { var mock = new Mock<AbstractBase>(); var notificationMock = entityMock.As<INotifyPropertyChanged>(); var propertyChang
我正在编写单元测试,并在尝试从抽象类模拟中提出事件时收到异常。 以下是示例代码: public abstract class AbstractBase : EntityObject {} [TestMethod] public void MyTest() { var mock = new Mock<AbstractBase>(); var notificationMock = entityMock.As<INotifyPropertyChanged>(); var propertyChangedMapper = new PropertyChangedMapper(); bo