Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

I need an insight into 'Static'

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AA2e72E - 11 Mar 2008 09:35 GMT
I am trying to understand why this works ...

using (Process ProcRegEdit = Process .Start("REGEDIT.EXE", "/s
C:\\Ajay\\VS2005\\C#\\REGISTRY\\ajay.reg"))
  {

    ProcRegEdit.WaitForExit(); // Wait indefinitely
    if (ProcRegEdit.HasExited)
        {
         ProcRegEdit.Close();
        }

... but this does not.

           using (Process ProcRegEdit = new Process())
           {
               ProcRegEdit.Start("REGEDIT.EXE", "/s
C:\\Ajay\\VS2005\\C#\\REGISTRY\\ajay.reg");
               ProcRegEdit.WaitForExit(); // Wait indefinitely
                 if (ProcRegEdit.HasExited)
               {
                   ProcRegEdit.Close();
               }

           }
/* NOTES
This line ...

ProcRegEdit.Start("REGEDIT.EXE", "/s
C:\\Ajay\\VS2005\\C#\\REGISTRY\\ajay.reg");

... generates a build error with the following message

Static member 'member' cannot be accessed with an instance reference;
qualify it with a type name instead
*/

Thanks.
Jon Skeet [C# MVP] - 11 Mar 2008 09:43 GMT
> I am trying to understand why this works ...

<snip>

> This line ...
>
[quoted text clipped - 5 lines]
> Static member 'member' cannot be accessed with an instance reference;
> qualify it with a type name instead

You've used ProcRegEdit.Start instead of Process.Start. You aren't
allow to try to use a static member (which Start is) as an instance
member - it can lead to confusion and very misleading code.

As a side note, it would be clearer which calls were static and which
were instance if you'd use camel case for your variable - procRegEdit
instead of ProcRegEdit.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Roger Frost - 11 Mar 2008 09:56 GMT
> [...]
>
[quoted text clipped - 9 lines]
>
>[...]

The general idea behind a static member is to have a helper method that
doesn't need an instance in memory to do it's job.  You can think of them as
synonymous to library routines.  They are members of the Class and not the
Object.

In your case that works, you are starting regedit in a new process and
giving that process a friendly name.

In your case that does not work, you are (in logic) creating a process then
trying to start regedit in it.  But regedit (or whatever the case may be)
needs it's own process.

It's a bit more complicated but this is the basic idea.

Signature

Roger Frost
"Logic Is Syntax Independent"

AA2e72E - 11 Mar 2008 10:18 GMT
Thanks for the explanations.

I think with the statement <they are members of the Class and not the Object
> I chave grasped the implications.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.