Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie syntax question
Message
From
21/09/2010 09:44:04
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Newbie syntax question
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01482146
Message ID:
01482146
Views:
117
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.
Next
Reply
Map
View

Click here to load this message in the networking platform