|
Along with what Pete said in the above reply about the using construct, implementing IDisposable helps automatic tools detect potential memory leaks. In your example, your class contains a disposable object. If the dispose method on your class never gets called, the image will not be disposed and the unmanaged resource will leak. When you implement IDisposable, tools have a better chance of detecting such leaks.
As an aside, you should not have a class finalizer (the ~A()) method unless you directly own an unmanaged resource such as a file handle stored as an IntPtr. The IDisposable classes you own as fields will have their own finalizer to take care of the unmanaged resources. Having unnecessary finalizers decreases the efficiency of the garbage collector.
|
|
|
|
|
Gideon Engelberth wrote: As an aside, you should not have a class finalizer (the ~A()) method unless you directly own an unmanaged resource such as a file handle stored as an IntPtr. The IDisposable classes you own as fields will have their own finalizer to take care of the unmanaged resources. Having unnecessary finalizers decreases the efficiency of the garbage collector.
I agree mainly as it is a valid information, but he get's around this problem, as he is using:
GC.SuppressFinalize(this);
By calling the "SuppressFinalize", the GC will not move the object to the finalization queue, and so prefent the double lookup of the object.
All the best,
Martin
|
|
|
|
|
He does, but only when the user has called Dispose. And since the class didn't implement IDisposable there is a higher probability that objects would not have been disposed. (At least where I've worked there tend to be plenty of programmers who fail to include try-finally blocks where necessary for correctness, as they (I believe) work based on the idea that if it runs OK on their machine this means the code is "correct" - a notion it would be useful to disspell from our profession imho.)
|
|
|
|
|
dojohansen wrote: And since the class didn't implement IDisposable there is a higher probability that objects would not have been disposed.
Second that! I wouldn't like to see such an implementation in my projects as it makes no sence not to implement IDisposable.
I just wanted to point to the "SuppressFinalize", also for the cases were you have to worry about your unmanaged recources.
All the best,
Martin
|
|
|
|
|
That's the main hit, but there is still a small hit from the fact that it has to be put on the finalization list in the first place (and then taken back off in Dispose). I have no idea how big that hit is, since that will depend mostly on how many of these objects are being created.
|
|
|
|
|
How can I get a single character without pressing enter in C#, something like _getch in C++? Tried with Console.Read, but still have to press enter to continue.
|
|
|
|
|
Have you tried Console.ReadKey()?
Life is a stage and we are all actors!
|
|
|
|
|
How I can get value of tag <!-- Hi World --> by C# codes.
I have used this code but it gives me error !
Code :
string b = node.SelectSingleNode("<!--").InnerText;
<code></code>error : Expression must evaluate to a node-set.
I can get <value>dsf and and <comment> with this code.
string a = node.SelectSingleNode("comment").InnerText;
|
|
|
|
|
Hi,
the selectSingleNode-method expects a string containing a xpath-expression. See here:
<a href="http://msdn.microsoft.com/en-us/library/h0hw012b%28VS.80%29.aspx">http://msdn.microsoft.com/en-us/library/h0hw012b%28VS.80%29.aspx</a>[<a href="http://msdn.microsoft.com/en-us/library/h0hw012b%28VS.80%29.aspx" target="_blank" title="New Window">^</a>]
So the second line you posted is a correct xpath-expression.
So with this xpath-expression:
<code>
/mynode/comment()
</code>
you select all comments within the node mynode. To access the first comment use:
<code>
/mynode/comment()[1]
</code>
This should do the trick.
Regards
Sebastian
|
|
|
|
|
Sorry I didnt get your idea
how can i get the value of
would you explaine more.....
in my Resource file i have this tags
<value>Ok
<comment>button Ok
<value>0,0
<comment>button Ok
<value>75, 23
<comment>button Ok
|
|
|
|
|
Is this an xml-file? Okay let us assume your file looks like this:
<br />
<resources><br />
<item><br />
<tag1>OK</tag1><br />
<tag2>button OK</tag2><br />
<!-- button2 --><br />
</item><br />
<item><br />
<tag1>0,0</tag1><br />
<tag2>button OK</tag2><br />
<!-- button2 --><br />
</item><br />
<item><br />
<tag1>75,23</tag1><br />
<tag2>button OK</tag2><br />
<!-- button2 --><br />
</item><br />
</resources><br />
Then you can get the first comment with (with itemNode is set to the first node with the tag item):
<br />
string b = itemNode.SelectSingleNode("./comment()[1]").InnerText<br />
Does this help you?
Regards
Sebastian
|
|
|
|
|
Thanks a Lot !!!!!!!!!!!!!!!
it was great help to me
|
|
|
|
|
You can't get this value as far as I know. You can put this value in a hidden label, than get this value.
modified 27-May-14 5:05am.
|
|
|
|
|
Hello,
I have a problem:
I want to draw a line between object A (Say an ellipse) and object B (also an ellipse). Now, between those object lies object C (which is a triangle). Now how can I draw the shortest line between A and B avoiding object C, using GDI+?
Thanks in advance,
Zaegra
Motivation is the key to software development.
|
|
|
|
|
In two steps:
1) Solve the mathmatical formula to determine the line's endpoints
2) Draw the line
I can't tell from your question which of the two steps you need help with, but it seems like you are asking for help with step 1. If you already know how to do step 2, then this is the wrong forum to ask your question as part 1 is not C# related.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
I have a datatable(code behind datatable class) that contains a column with the name aa which have ulphanumeric values.
Is there any way to find those rows having numeric values onlywithout doing iteration ?
|
|
|
|
|
The Select method of the DataTable class allows you to do just that, using pseudo T-SQL.
It returns an array of DataRow .
E.g.:
DataRow[] results = yourDataTable.Select("aa=15");
var question = (_2b || !(_2b));
|
|
|
|
|
Thanks for replying..
Greg Chelstowski wrote: DataRow[] results = yourDataTable.Select("aa=15");
I have to check it at runtime, and there is no static value as written by you in query. the datatable can have any number of both numeric, alphanumeric records.
Please suggest something.
|
|
|
|
|
abcurl wrote:
I have to check it at runtime
???
abcurl wrote: and there is no static value as written by you in query
Then use variables. And by static I'm sure you meant hard-coded.
abcurl wrote: the datatable can have any number of both numeric, alphanumeric records.
Use single quotes in the query then!
Now, once you actually got your DataRow array, I'm sure you'll be asking next how to extract values from it. Look, do some reading on MSDN, there are a million tutorials and examples on the .Select method of DataTable.
var question = (_2b || !(_2b));
|
|
|
|
|
If possible try to use the Regex. May be it helps solving your problem.
|
|
|
|
|
I use below code for add picture to dataBase but if I need that insert null instead of picture into database the program give me Error (I set allowNull for column in Sql)
(it's neccesary becuase maybe user dosen't have picture for insert into database)
how can I do that?
MemoryStream mstr = new MemoryStream();
pictureBox1.Image.Save(mstr, pictureBox1.Image.RawFormat);
byte[]pic= mstr.GetBuffer();
SqlConnection sq=new SqlConnection(...);
SqlParameter sp1 = new SqlParameter("@pic", pic);
SqlCommand sc = new SqlCommand("insert into Info values(@pic)", sq);
sc.Parameters.Add(sp1);
sc.ExecuteNonQuery();
|
|
|
|
|
Hi,
could you post the error you receive (message etc.)? Maybe your db-schema doesn't allow null-values for the picture column.
Regards
Sebastian
|
|
|
|
|
I set allowNull for that column
|
|
|
|
|
And the error you receive is?
|
|
|
|
|
Error : parameter @pic, which was not supplied
|
|
|
|