Click here to Skip to main content
15,895,504 members
Home / Discussions / C#
   

C#

 
GeneralRe: Need help with my very first c# application Pin
Luc Pattyn7-Oct-10 9:55
sitebuilderLuc Pattyn7-Oct-10 9:55 
GeneralRe: Need help with my very first c# application Pin
S Houghtelin7-Oct-10 10:01
professionalS Houghtelin7-Oct-10 10:01 
GeneralRe: Need help with my very first c# application Pin
OriginalGriff7-Oct-10 9:20
mveOriginalGriff7-Oct-10 9:20 
GeneralRe: Need help with my very first c# application Pin
turbosupramk37-Oct-10 10:01
turbosupramk37-Oct-10 10:01 
GeneralRe: Need help with my very first c# application Pin
turbosupramk37-Oct-10 10:12
turbosupramk37-Oct-10 10:12 
GeneralRe: Need help with my very first c# application Pin
OriginalGriff7-Oct-10 21:34
mveOriginalGriff7-Oct-10 21:34 
GeneralRe: Need help with my very first c# application Pin
turbosupramk38-Oct-10 4:28
turbosupramk38-Oct-10 4:28 
GeneralRe: Need help with my very first c# application Pin
OriginalGriff8-Oct-10 4:51
mveOriginalGriff8-Oct-10 4:51 
Well done!Thumbs Up | :thumbsup:

I think you are getting there.

A couple of style things, that make it easier to read when you go back to it:
string[] arr = new string[] { "server1", "server2", "server3" }; // server names you want to ping
foreach (string i in arr)
Don't call it "i" - there are a couple of reasons (one of which is that old programmers assume "i" is always an int). Always use descriptive names for variables, it makes it a lot easier to work out what you are trying to do. Since Visual Studio list possible names for you, it isn't a lot of extra typing, and it does make it more readable. Try using "server" instead:
string[] servers = new string[] { "server1", "server2", "server3" }; // server names you want to ping
foreach (string server in servers)
   {
   ...
   }


And try using a for loop instead of a do...while - it makes it more obvious by keeping the whole thing together:
int pingloop = 0;
do
   {

   PingReply reply = pingSender.Send(i, timeout, buffer, options);
   if (reply.Status == IPStatus.Success)
       {
       Console.WriteLine("Reply from {0}", reply.Address.ToString() + ": bytes=" + reply.Buffer.Length + " time=" + reply.RoundtripTime + "ms" + " TTL=" + reply.Options.Ttl);
       pingloop = pingloop +1;
       }
   }
   while (pingloop < 4);
becomes
for (int retries = 0; retries < 4; retries++)
   {
   PingReply reply = pingSender.Send(i, timeout, buffer, options);
   if (reply.Status == IPStatus.Success)
       {
       Console.WriteLine("Reply from {0}", reply.Address.ToString() + ": bytes=" + reply.Buffer.Length + " time=" + reply.RoundtripTime + "ms" + " TTL=" + reply.Options.Ttl);
       break;
       }
   }
It's all about keeping thing together, and making it obvious what is going on. Doing it your way means that "pingloop" is available after the loop, implying that it will be relevant and probably used after the loop. With the for loop, "retries" is not available outside the loop at all.

I also added the "break" to prevent repeated pinging once it has succeeded.

Good effort though, well done!Cool | :cool:
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

GeneralRe: Need help with my very first c# application Pin
turbosupramk313-Oct-10 7:20
turbosupramk313-Oct-10 7:20 
GeneralRe: Need help with my very first c# application Pin
S Houghtelin7-Oct-10 9:16
professionalS Houghtelin7-Oct-10 9:16 
AnswerRe: Need help with my very first c# application Pin
Nish Nishant7-Oct-10 8:17
sitebuilderNish Nishant7-Oct-10 8:17 
AnswerRe: Need help with my very first c# application Pin
MasttsaM13-Oct-10 22:43
MasttsaM13-Oct-10 22:43 
QuestionAbout creating Editable(fillable) PDF-forms Pin
sameermaske7-Oct-10 4:04
sameermaske7-Oct-10 4:04 
AnswerRe: About creating Editable(fillable) PDF-forms Pin
Ennis Ray Lynch, Jr.7-Oct-10 6:26
Ennis Ray Lynch, Jr.7-Oct-10 6:26 
QuestionParsing a text file. Pin
jenya77-Oct-10 3:21
jenya77-Oct-10 3:21 
AnswerMessage Closed Pin
7-Oct-10 3:41
stancrm7-Oct-10 3:41 
GeneralRe: Parsing a text file. Pin
jenya77-Oct-10 3:57
jenya77-Oct-10 3:57 
GeneralRe: Parsing a text file. Pin
#realJSOP7-Oct-10 23:41
mve#realJSOP7-Oct-10 23:41 
AnswerRe: Parsing a text file. Pin
PIEBALDconsult7-Oct-10 16:28
mvePIEBALDconsult7-Oct-10 16:28 
QuestionMicrosoft.Office.Interop.Excel BorderAround2 crash Pin
Blubbo7-Oct-10 2:58
Blubbo7-Oct-10 2:58 
AnswerRe: Microsoft.Office.Interop.Excel BorderAround2 crash Pin
Dave Kreskowiak7-Oct-10 3:44
mveDave Kreskowiak7-Oct-10 3:44 
GeneralRe: Microsoft.Office.Interop.Excel BorderAround2 crash Pin
Blubbo7-Oct-10 4:02
Blubbo7-Oct-10 4:02 
GeneralRe: Microsoft.Office.Interop.Excel BorderAround2 crash Pin
Dave Kreskowiak7-Oct-10 4:42
mveDave Kreskowiak7-Oct-10 4:42 
GeneralRe: Microsoft.Office.Interop.Excel BorderAround2 crash Pin
Blubbo7-Oct-10 4:49
Blubbo7-Oct-10 4:49 
GeneralRe: Microsoft.Office.Interop.Excel BorderAround2 crash Pin
Dave Kreskowiak7-Oct-10 6:04
mveDave Kreskowiak7-Oct-10 6:04 

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.