Click here to Skip to main content
15,898,979 members
Home / Discussions / C#
   

C#

 
AnswerRe: Where in Toronto Ont Canada can I walk in and buy Visual Studio 2008 ? Pin
Ravi Bhavnani4-Mar-10 15:45
professionalRavi Bhavnani4-Mar-10 15:45 
AnswerRe: Where in Toronto Ont Canada can I walk in and buy Visual Studio 2008 ? Pin
PIEBALDconsult4-Mar-10 17:42
mvePIEBALDconsult4-Mar-10 17:42 
Questionhow to read and write to xml using dataset [modified] Pin
xiaowenjie4-Mar-10 12:51
xiaowenjie4-Mar-10 12:51 
AnswerRe: how to read and write to xml using dataset Pin
snorkie4-Mar-10 16:37
professionalsnorkie4-Mar-10 16:37 
GeneralRe: how to read and write to xml using dataset Pin
xiaowenjie4-Mar-10 21:47
xiaowenjie4-Mar-10 21:47 
AnswerRe: how to read and write to xml using dataset Pin
shawnzhang4-Mar-10 19:26
shawnzhang4-Mar-10 19:26 
QuestionRemoving All "List<*>" Items Though It Shouldn't ... ?? [SOLVED] Pin
Matt U.4-Mar-10 12:36
Matt U.4-Mar-10 12:36 
AnswerRe: Removing All "List" Items Though It Shouldn't ... ?? Pin
Luc Pattyn4-Mar-10 14:54
sitebuilderLuc Pattyn4-Mar-10 14:54 
Hi Matt,

I didn't spot the problem you reported right away; however I do have lots of comments, I'll give you some here, as I hope they will inspire you; taking care of them should simplify your code, possibly also eliminating the problem:

1.
Your Artist class is holding strings, even for items that basically are not strings: UniqueID would be better of being an int, HourlySessionRate probably needs to be a float/double/decimal, maybe an int, but not a string.
And yes, that means you need to use a Parse/TryParse method to convert user input to a number, and also ToString() to turn a number to a string for output purposes; but then you can use the numbers to perform calculations, indexing, etc.

2.
you have too many safety tests. Examples:
a) a constructor (e.g. Artist) should either return a real object, or throw an exception; it should never return null.
b) no need to test for an empty list, a foreach will just be skipped when the list is empty.

3.
I tend to name collections by using the plural of the type name they contain. So "students" would be an array, a list, a queue, whatever, holding Student instances. And I don't include "array", "list" or whatever, so I can easily change my mind later on.

4.
Since UniqueID is an important field to your Artist class, why not store Artist instances in a Dictionary<int, Artist> collection? That eliminates searches by UniqueID, just do Artists[UniqueID] as a dictionary can be indexed just like an array.

5.
at the end of btnDelete_Click, you have a foreach loop which attempts to modify the collection you are enumerating; that won't work, as a removal invalidates the enumerator. I expect it throws an exception.

6.
you seem to have several methods that return a bool to indicate success/failure. Most often that is not the best way to do error checking as it forces you to write extra code on every invocation; if you forget some, errors will go unnoticed. The modern way if dealing with this, is by throwing an Exception when something went wrong; then the caller can get that information using one or more try-catch blocks. If you're unfamiliar with them, take the time to read up on it, it comes in very handy.

7.
when catching an exception, NEVER ignore it; either solve the situation in your app, or at the very least report it somewhere, using all available information.
try {
   ...
} catch(Exception exc) {
   Console.WriteLine(exc.ToString());
}

is what I do most of the time. It will tell you exactly what went wrong and where, up to the source line.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.

GeneralRe: Removing All "List" Items Though It Shouldn't ... ?? Pin
Matt U.4-Mar-10 15:19
Matt U.4-Mar-10 15:19 
GeneralRe: Removing All "List" Items Though It Shouldn't ... ?? Pin
Luc Pattyn4-Mar-10 15:27
sitebuilderLuc Pattyn4-Mar-10 15:27 
GeneralRe: Removing All "List" Items Though It Shouldn't ... ?? Pin
Matt U.4-Mar-10 15:56
Matt U.4-Mar-10 15:56 
GeneralRe: Removing All "List" Items Though It Shouldn't ... ?? Pin
Luc Pattyn4-Mar-10 16:06
sitebuilderLuc Pattyn4-Mar-10 16:06 
GeneralRe: Removing All "List" Items Though It Shouldn't ... ?? Pin
Matt U.5-Mar-10 11:37
Matt U.5-Mar-10 11:37 
GeneralRe: Removing All "List" Items Though It Shouldn't ... ?? Pin
Luc Pattyn5-Mar-10 12:00
sitebuilderLuc Pattyn5-Mar-10 12:00 
GeneralRe: Removing All "List" Items Though It Shouldn't ... ?? Pin
Matt U.5-Mar-10 12:04
Matt U.5-Mar-10 12:04 
QuestionChanging colors of an image Pin
Berlus4-Mar-10 9:34
Berlus4-Mar-10 9:34 
AnswerRe: Changing colors of an image Pin
Anubhava Dimri4-Mar-10 18:14
Anubhava Dimri4-Mar-10 18:14 
QuestionWinsock Library Recommendation? [modified] Pin
Richard Andrew x644-Mar-10 9:13
professionalRichard Andrew x644-Mar-10 9:13 
AnswerRe: Winsock Library Recommendation? Pin
snorkie4-Mar-10 10:22
professionalsnorkie4-Mar-10 10:22 
GeneralRe: Winsock Library Recommendation? Pin
Richard Andrew x644-Mar-10 10:29
professionalRichard Andrew x644-Mar-10 10:29 
AnswerRe: Winsock Library Recommendation? Pin
snorkie4-Mar-10 11:22
professionalsnorkie4-Mar-10 11:22 
GeneralRe: Winsock Library Recommendation? Pin
Richard Andrew x644-Mar-10 11:31
professionalRichard Andrew x644-Mar-10 11:31 
GeneralRe: Winsock Library Recommendation? Pin
snorkie4-Mar-10 16:30
professionalsnorkie4-Mar-10 16:30 
AnswerRe: Winsock Library Recommendation? Pin
Ennis Ray Lynch, Jr.4-Mar-10 11:41
Ennis Ray Lynch, Jr.4-Mar-10 11:41 
Questionfiles name of a directory in a lable one by one Pin
tanweer4-Mar-10 9:11
tanweer4-Mar-10 9:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.