| |

VerySource

 Forgot password?
 Register
Search
View: 8|Reply: 3

Confusion about the static keyword?

[Copy link]

2

Threads

6

Posts

7

Credits

Newbie

Rank: 1

Credits
7

 Asia/Pacific Region

Post time: 2020-3-10 00:30:01
| Show all posts |Read mode
I start a thread in a class and run a function as follows:
public Thread th = new Thread (new ThreadStart (process));
Then I defined a function process, as follows:
static void process ()
{
    this.InstallProcess (this.ApplicateName, this.ApplicateArgument);
    th.Start ();
}
The problem arises, I want to call another function InstallProcess in the same class in the process, I do n’t know if it works, I ca n’t compile it with the wording above, and I ca n’t use the keyword this, so I did Method. I now want to know, can I call the installProcess function in this static function process, and can I use the variables outside it? I wonder if I made it clear
Reply

Use magic Report

0

Threads

2

Posts

3

Credits

Newbie

Rank: 1

Credits
3

 Invalid IP Address

Post time: 2020-6-2 20:45:01
| Show all posts
Static functions are intended to be functions that can be used without generating object instances
So it doesn't hold this, this should be a reference to this object instance

If you want to call the method in this object, you can refer to the writing of the MAIN function to generate the object
Such as: Class A
A objecta = new A();
objecta.installProcess();

You can also write the installProcess function as a static function
Reply

Use magic Report

0

Threads

13

Posts

11

Credits

Newbie

Rank: 1

Credits
11

 China

Post time: 2020-6-4 09:30:01
| Show all posts
Upstairs, lz obviously wants to process the value of the object through installProcess, is it not the same problem if installProcess is static?

The landlord can try it with asynchronous delegation, which is a bit simpler.
Reply

Use magic Report

2

Threads

6

Posts

7

Credits

Newbie

Rank: 1

Credits
7

 Asia/Pacific Region

 Author| Post time: 2020-6-17 08:15:01
| Show all posts
Haha, thank you.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list