Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Newbie syntax question
Message
De
21/09/2010 09:44:04
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Newbie syntax question
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01482146
Message ID:
01482146
Vues:
116
HI All!

I am learning C# .Net and have a syntax question.

The sample code in the training course require a for loop to display some settings, EG ;
    Process notepadProcess = new Process();
    ProcessStartInfo notepadProcessStartInfo = new ProcessStartInfo("notepad.exe");

    notepadProcess.StartInfo= notepadProcessStartInfo;
    notepadProcess.Start();
    System.Threading.Thread.Sleep(1000);

   ProcessModuleCollection processModuleCollection = notepadProcess.Modules;                        
   foreach(ProcessModule processModule in processModuleCollection)
   {
   }
What I don't know and the course video does not say is why the steps to store the modules collection to a variable is required.

Coming from a VFP background, if the collection is a property of an object I would just access that collection "directly", EG;
    Process notepadProcess = new Process();
    ProcessStartInfo notepadProcessStartInfo = new ProcessStartInfo("notepad.exe");

    notepadProcess.StartInfo= notepadProcessStartInfo;
    notepadProcess.Start();
    System.Threading.Thread.Sleep(1000);

    foreach (ProcessModule processModule in notepadProcess.Modules)
   {
   }
If there a .Net reason for doing it this way? this is just one example, but there are lots through the samples of whenever there is a collection to address it is first stored to a variable.


Gary.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform