Click here to Skip to main content
15,887,776 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to bind control’s properties to variables in C#? Pin
PomaPomaPoma3-Feb-10 11:12
PomaPomaPoma3-Feb-10 11:12 
AnswerRe: How to bind control’s properties to variables in C#? Pin
Not Active3-Feb-10 9:32
mentorNot Active3-Feb-10 9:32 
GeneralRe: How to bind control’s properties to variables in C#? Pin
PomaPomaPoma3-Feb-10 10:09
PomaPomaPoma3-Feb-10 10:09 
GeneralRe: How to bind control’s properties to variables in C#? Pin
Not Active3-Feb-10 10:17
mentorNot Active3-Feb-10 10:17 
QuestionC# code clean up and improvement Pin
eeffoc423-Feb-10 5:20
eeffoc423-Feb-10 5:20 
AnswerRe: C# code clean up and improvement Pin
Luc Pattyn3-Feb-10 5:26
sitebuilderLuc Pattyn3-Feb-10 5:26 
GeneralRe: C# code clean up and improvement [modified] Pin
eeffoc423-Feb-10 5:50
eeffoc423-Feb-10 5:50 
GeneralRe: C# code clean up and improvement Pin
Luc Pattyn3-Feb-10 6:26
sitebuilderLuc Pattyn3-Feb-10 6:26 
Hi again,

looks pretty good overall. I have a couple of remarks:

functionality & behavior

1.
Right now your code first gathers all info, then displays it. It might be more user-friendly to intertwine those actions, so you can see the info parts as soon as they are available. More on this later.

structure

2.
You might want to split the functionality into a method gathering information (maybe returning a list of strings), and one displaying the information. So you later on can more easily change one or the other. Disadvantage: you don't see anything until all has been gathered. Possible fix: make a gather method and give it a delegate, so it can report without knowing how the report is actually done (works like a function pointer in C/C++). My Sokoban article is an example, search for "Logger".

coding

3.
your overall coding style is OK.

4.
A queue is a bit of an odd choice, a simple List<string> would behave identically here. Nothing wrong though.

5.
Objects (such as those ManagementClass instances) that have a Dispose() method and are no longer needed should be disposed of. So your code should have a try-finally where the finally tests for null and disposes. This improves the memory footprint, and for some classes is needed for correct operation. Not disposing is (almost) a bug.

6.
it would be more logical to do input validation first, so move ValidateHostInput(hostName) up. Also check the textbox contents early on.

7.
in .NET one normally throws exceptions on bad inputs, rather than just returning. Only in special cases, .NET also provides a non-throwing alternative (see int.Parse and int.TryParse).

8.
I find it strange the line IPAddress[] myIP = Dns.GetHostAddresses(target); was left outside the try block.

9.
Having try-catch without explicitly specifying exception type isn't good practice. I tend to report at two levels: a functional level (which you have), and a technical level, probably providing the whole Exception.ToString() result, which is many lines, but would help the technical people to pinpoint what caused the problem.


You passed; up to the next level!

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.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]


GeneralRe: C# code clean up and improvement Pin
eeffoc423-Feb-10 9:17
eeffoc423-Feb-10 9:17 
GeneralRe: C# code clean up and improvement Pin
Luc Pattyn3-Feb-10 9:54
sitebuilderLuc Pattyn3-Feb-10 9:54 
AnswerRe: C# code clean up and improvement Pin
Md. Marufuzzaman3-Feb-10 6:27
professionalMd. Marufuzzaman3-Feb-10 6:27 
Questionasalamalikum! Pin
ayeshazahoor3-Feb-10 4:43
ayeshazahoor3-Feb-10 4:43 
Questionhello every one Pin
japrasath3-Feb-10 4:03
japrasath3-Feb-10 4:03 
AnswerRe: hello every one Pin
tonyonlinux3-Feb-10 4:13
tonyonlinux3-Feb-10 4:13 
AnswerRe: hello every one Pin
Not Active3-Feb-10 4:33
mentorNot Active3-Feb-10 4:33 
AnswerRe: hello every one Pin
Abhinav S3-Feb-10 5:47
Abhinav S3-Feb-10 5:47 
AnswerRe: hello every one Pin
Wamuti3-Feb-10 9:07
Wamuti3-Feb-10 9:07 
QuestionInserting a record into a Multi-table database using linq to sql in c# [modified] Pin
tonyonlinux3-Feb-10 3:58
tonyonlinux3-Feb-10 3:58 
AnswerRe: Inserting a record into a Multi-table database using linq to sql in c# Pin
Not Active3-Feb-10 4:35
mentorNot Active3-Feb-10 4:35 
QuestionForms Slowness Pin
Syed Shahid Hussain3-Feb-10 3:09
Syed Shahid Hussain3-Feb-10 3:09 
AnswerRe: Forms Slowness Pin
OriginalGriff3-Feb-10 3:19
mveOriginalGriff3-Feb-10 3:19 
GeneralRe: Forms Slowness Pin
Syed Shahid Hussain3-Feb-10 3:28
Syed Shahid Hussain3-Feb-10 3:28 
GeneralRe: Forms Slowness Pin
OriginalGriff3-Feb-10 3:39
mveOriginalGriff3-Feb-10 3:39 
GeneralRe: Forms Slowness Pin
Syed Shahid Hussain3-Feb-10 3:48
Syed Shahid Hussain3-Feb-10 3:48 
GeneralRe: Forms Slowness Pin
Luc Pattyn3-Feb-10 3:51
sitebuilderLuc Pattyn3-Feb-10 3:51 

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.