|
Presumably, you have a huge list if you're using an Int64 ?
My guess would be that an int can be compared to an int, nice and easy. If you have two datarows, you need to look up a value in both before you can do a comparison. Or am I wrong, you're just checking if two datarows are references to the same object ? Either way, you've gone from POD to a complex type being passed around and compared.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
the Int64 is just a key, it does not reflect large amounts of data.
When I'm comparing DataRows I'm checking 3 columns (worst case), and I'm doing this to maintain
a sorted list. This is so I can drop the 'smallest' entry off.
You said that I'm now passing a complex type around - This is a DataRow, therefore its 'reference' is passed around only, surely this can not be much bigger than an Int64.
|
|
|
|
|
That's true, it's the cost of comparison that I was focused on.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I am working with the new FlatAppearance class under the
System.Windows.Forms.Button control in 2.0 and am creating a flat button. I
set the button FlatStyle to Flat and the FlatAppearance.BorderSize to 1.
When I run the app the border is exactly 2 pixels and not 1.
Is there anolther property you are suppose to set on the control or is this
simply a bug?
Thanks,
Anton
|
|
|
|
|
Hi,
can anyone offer some pros as to why raise an exception?
Imagine Im developing a function. I can either account for errors by using a try...catch statment, or I can raise an exception.
But Im missing the point of an raising an exception. I can understand why it occurs, but not for reason in the real world.
If I development a function that requires a integer parameter to be less than 10, why would I need to create an exception if its greater? Surely Im going to be aware of that myself? Likewise, I would much rather the application deal with the problem using a try...catch, than throw an exception causing it to creash.
So therefore, raising exceptions is bad?
Can anyone offer any thoughts?
Mark
|
|
|
|
|
One of the best reasons to use exceptions is to make the method that is calling your method aware that something has gone wrong and needs to be dealt with.
Suppose you have written a method that writes a file to disk. Now let's assume that for whatever reason, the file can't be written to disk (disk is full, network error etc.).
Now how should your method handle these errors. You can of course pop up a messagebox explaining to user what has gone wrong, but your calling method will never be aware of the error (unless you return a status code of some kind). You could choose to try to handle the error in the called method, but it is possible that your method can't resolve the error. In that case it is better to make your calling method responsible for handling this.
So the best way to handle these situations is as follows (pseudo code)
try<br />
{<br />
}<br />
catch (ArgumentException e)<br />
{<br />
}<br />
catch (Exception e)<br />
{<br />
throw e;<br />
}
Regards,
Nico
p.s.
Which of the Code Project gurus around here can tell me how to make the tabs in my example code visible. It looks horribly unindented now...
|
|
|
|
|
Nico van der Plas wrote: p.s.
Which of the Code Project gurus around here can tell me how to make the tabs in my example code visible. It looks horribly unindented now...
Use the pre tag.
---
b { font-weight: normal; }
|
|
|
|
|
Mark06 wrote: Imagine Im developing a function. I can either account for errors by using a try...catch statment, or I can raise an exception.
You should only catch exceptions that you know how to handle within the function. A try/catch around all your functions is a bad idea.
Mark06 wrote: If I development a function that requires a integer parameter to be less than 10, why would I need to create an exception if its greater?
So the calling function knows why you couldn't process it's input.
Mark06 wrote: So therefore, raising exceptions is bad?
That depends, would you prefer the program to crash on your machine, or on your users ? When an exception occurs, it indicates that a situation has arisen in your code which you've not properly handled.
FWIW, any windows program I write handles exceptions at the top level and writes them to a log file, exceptions are also exceptionally useful at helping me to work out why code that runs fine here, doesn't always work in the real world. Code that swallowed exceptions would not give me that information, and would make my life a lot more difficult.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Mark06 wrote: I can either account for errors by using a try...catch statment, or I can raise an exception.
They are actually two sides of the same coin. You use try...catch to handle a sitation where an exception has been raised.
Exceptions are used to handle error messages that can travel up through the call stack until there is some code that knows how to handle it. If you for example have a function that takes a string as argument, and someone sends a null to the function, you can throw an ArgumentNullException to flag that an error has occured as you can't do anything meningfull with the argument. The code that called the function may anticipate that this might happen and catch the exception, or it can let the excpetion continue through the call stack to be handled at a higher level.
Mark06 wrote: If I development a function that requires a integer parameter to be less than 10, why would I need to create an exception if its greater? Surely Im going to be aware of that myself? Likewise, I would much rather the application deal with the problem using a try...catch, than throw an exception causing it to creash.
Perhaps you are not aware of an error that causes some code to send a higher value, then throwing an exception is a good way of telling exactly what went wrong. You can of course choose to handle it some other way, like clipping the values that are larger, but that depends on what you want to happen. Sometimes you want an error to cause an exception, so that you can fix it, instead of silently changing the value or returning an incorrect value that will cause problems later in the code.
---
b { font-weight: normal; }
|
|
|
|
|
Exceptions are for that moron that will modify your code. Always raise good exceptions (your own type too) always use if checks if an exception can be avoided, Assertions are your friend.
90% of the cost is maintenance. Make your code easy to maintain and your code will be great.
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
Hi All!
How can i get the duration of a song?
I have the Windows Media Player control in my Project but i do not know to get the duration, i found the curentMedia properity but it does not work.
Do you know?
Or is there another way to do so?
Thanks
|
|
|
|
|
There's a dll called dexter.dll in your system32 folder if you have DX. Import a reference to it. It contains a class called the MediaDetClass. You can create an instance of this class using the path to your video file, and it's properties will include a stream length. I have found no way to get the video size or length from the WMP classes.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
Use This ......
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand,StringBuilder strReturn,int iReturnLength, IntPtr hwndCallback);
public int Duration()
{
int ReturnSeconds;
sCommand = "status MediaFile length";
private StringBuilder sBuffer = new StringBuilder(128);
mciSendString(sCommand, sBuffer, 128, IntPtr.Zero);
ReturnSeconds = Convert.ToInt32((sBuffer.ToString()));
ReturnSeconds = ReturnSeconds/1000;
return ReturnSeconds;
}
It will return you the duration .....
Enjoy!!!!
<marquee>nishu
|
|
|
|
|
I am write code that print some lines and text.
In dialog box of printing , I am printing to file - "print to file".
how can I print this file now to the printer???
If i drag him to the menneger of printing it did not working
he write to me : "Can No Print this file,try to open with an apliction..."
when I save this file , what kind of extension I need to write ? ? ?
I mast an answer
Galigal156
|
|
|
|
|
I need your help guys. Thanks in advance.
Can you please teach me on how to create a string array property or give a snippet/sample code. I need this property to have a string editor for my custom web control.
|
|
|
|
|
Hello
Mark Anthony Sabado wrote: how to create a string array property
private string[] _myarray;
public string[] MyStringArray
{
get { return _myarray; }
set { _myarray = value; }
}
Was that what you were looking for?
Regards
|
|
|
|
|
|
Hello,
Maybe 'System.Collections.Specialized.StringCollection' can help you somehow, to make your code more dynamic.
private System.Collections.Specialized.StringCollection _mystringcollection = new System.Collections.Specialized.StringCollection;
public System.Collections.Specialized.StringCollection MyStringCollection
{
get
{
return _mystringcollection;
}
set
{
_mystringcollection = value;
}
}
All the best,
Martin
|
|
|
|
|
Well, i can succesfully get to the database, but get the error 'doesn't exist or access denied'
The problem is that the DB requires a username and password.
With ftp that I was checking out earlier this was in credentials, but i don't see that here, i'll keep looking but any help or articles that you can direct me to would be really great.
|
|
|
|
|
Take a look at connectionstrings.com[^], they have lots of examples for various connection strings for almost every database.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Thanks, thats really usefull
|
|
|
|
|
I am trying to install (with MSI) a Document to "My Documents" for the current user. So I need to do something like c:\Documents and Settings\[UserName]\My Documents as the DefaultDirectory. How do I get the User name in an Install?
|
|
|
|
|
I asked this a while ago, its quite simple really
string mydocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
the key part is obviously the environment.getfolderpath part, theres quite a few 'special folders' that are in there quite usefull
|
|
|
|
|
Sure in code. But I was talking about an install project. There is a property for a folder called DefaultDirectory. I havn't done very many installs and the ones I have done are pretty straight forward so I could be missing something.
|
|
|
|
|
Hello
You can make an exe file that will copy the files you want to "My Documents" using C# code, and excute it during/after your installation as a custom action.
Regards
|
|
|
|