|
hai,
how to do vote rating concept in .net with c#.if you know the concept or link send to me..
thank you.
|
|
|
|
|
If we understood the question it would help.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hello everyone,
For this best practices rule,
http://msdn.microsoft.com/en-us/ms182172.aspx
What are the benefits of following this rule even if I am not wrapping an unmanaged resource, like FileStream in the sample in the page.
I think it is fine if the class does not implement IDisposable, since FileStream could be disposed (to release the native file handle) since it has its own Dispose method. Any ideas?
thanks in advance,
George
|
|
|
|
|
George_George wrote: What are the benefits of following this rule even if I am not wrapping an unmanaged resource,
No benefit. If you have nothing to dispose, why implement IDisposable ?
|
|
|
|
|
Thanks N a v a n e e t h!
In the MSDN sample, what is the benefit of class HasDisposeMethod, if it implements IDisposable (as shown in the sample)?
regards,
George
|
|
|
|
|
It wraps FileStream and provides dispose pattern to dispose FileStream instance. In that example, they have initialized FileStream, but not disposing after use. When you call Dispose() on a HasDisposeMethod instance, FileStream instance will get disposed. If HasDisposeMethod was like the following, no need of IDisposable implementation.
public class HasDisposeMethod
{
public HasDisposeMethod()
{
}
public void UseFileStream()
{
using(FileStream newFile = new FileStream(@"c:\temp.txt", FileMode.Open))
{
}
}
} In the above example, FileStream instance is used and disposed after user. So no need to provide dispose interface.
|
|
|
|
|
Thanks N a v a n e e t h,
Great reply! One further question, for the original sample in the MSDN page, if it does not implement IDisposable, what are the issues?
regards,
George
|
|
|
|
|
FileStream won't be disposed until GC collects.
|
|
|
|
|
Thanks N a v a n e e t h!
So, you mean the benefit is -- if the wrapper class implements IDispoable, we could enforce "using" block on the wrapper class to Dispose the resource immediately?
regards,
George
|
|
|
|
|
Yes. It's always good to call Dispose() if it is provided.
|
|
|
|
|
Great N a v a n e e t h!
Question answered.
regards,
George
|
|
|
|
|
This issue is with respect to Windows Application
I have 2 comboBox in the same row of a DatagridView. When I attach an event one of them, the other comboBox also fires the same event. How can I attach an event only to a particular combo in a DataGridView
|
|
|
|
|
Make use of the sender argument. Check sender is the required combobox. If yes, continue processing.
|
|
|
|
|
what's the diffrence between these two declarations:
ObjectType objectName;
ObjectType objectName=null;
|
|
|
|
|
The first statement means that you are going to declare an object and the second statement mean you are going to dispose an object. If you want to dispose an object then you assign null to that object.
|
|
|
|
|
arslanjatt wrote: The first statement means that you are going to declare an object and the second statement mean you are going to dispose an object. If you want to dispose an object then you assign null to that object.
This not correct. Both means same. Also you don't need to assign NULL to an object which you want to dispose. It is handled automatically and an object will be garbage collected when nothing is referring it.
|
|
|
|
|
Hi Navaneeth,
Do developers consider it good practise to always initialise an instance to null when they are declared?
For example, if I always declared variables, and set them to null as below:
<br />
Class class1 = null;<br />
would it be bad practice and/or any slower than:
<br />
Class class1;<br />
|
|
|
|
|
Hello Mark,
MarkBrock wrote: Do developers consider it good practise to always initialise an instance to null when they are declared?
I am not sure, but I never used to assign NULL when it is declaring.
object obj;
object obj1 = null;
Console.WriteLine(obj == null);
Console.WriteLine(obj1 == null); This won't compile. Compiler will give error saying obj is not assigned. So easily I can find out uninitialized variables. But if you assign NULL to it and forget to initialize, compiler won't give any error, but you will end with a NullReferenceException at the runtime. I think performance wise there won't be any difference.
|
|
|
|
|
It's not good practice to initialize a variable to null in .NET because it's already done automatically by the CLR. It just wastes an instruction because it's redundant and unnecessary. See Effective C# by Bill Wagner.
|
|
|
|
|
so they're the same in memory but not in cpu usage you mean?
|
|
|
|
|
|
|
Alan!I wanted to mark ur anwer as reply or sth like that,and I clicked
report this message link
is there any way to undo it?
|
|
|
|
|
Ah, so THAT'S why the Code Project agents showed up at my place with a warrent!
|
|
|
|
|
They both are same. If you are using first one, compiler will give error. But for second one, you will get error only in the runtime.
modified on Tuesday, June 17, 2008 3:18 AM
|
|
|
|