| |

VerySource

 Forgot password?
 Register
Search
View: 1023|Reply: 6

The difference between Shared, Public, etc.

[Copy link]

2

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-11-4 12:00:01
| Show all posts |Read mode
Shared
Public
Protected
Friend
Private
...

The scope of application, please give a simple example to illustrate
Reply

Use magic Report

2

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-11-4 12:15:01
| Show all posts
Can use the scope of the current class, project, etc.
Reply

Use magic Report

0

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-11-4 15:15:02
| Show all posts
public, private, protect are the scope of variable
Shared variables are similar to application global variables.
Reply

Use magic Report

0

Threads

9

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-11-4 21:00:01
| Show all posts
Shared is similar to static
Reply

Use magic Report

1

Threads

23

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-11-4 21:30:02
| Show all posts
Shared declares static global variables, multi-threaded can be used as safe variables
Public global variable, this variable can be used wherever it is declared
Protected seems to be used for declaring attributes, right? Preceded by public is globally visible, plus private module is visible inside
Friend doesn't know this thing very much, it is used in front of the attribute. . . Not used
Private local variables can only be seen in this module, and their functions are basically the same as dim. . . But no one declared that the method should use dim. . . This is the difference.
Reply

Use magic Report

1

Threads

8

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-11-4 22:00:01
| Show all posts
Class Employee
    Public name As String
    Private salary As Double
End Class

Module MDLTest
    Sub Main()
        Dim c As New Employee
        c.name = "John"
        'Error:
        'c.salary = 100403.33
    End Sub
End Module
-------------------------------------------------- -------------
Class Client
    Public prefix As String
    Public name As String
    Public Shared printPrefix As Boolean = True
    Sub PrintName()
        If printPrefix Then Console.Write(prefix)
        Console.WriteLine(name)
    End Sub
End Class

Module MDLTest
    Sub Main()
        Dim x As New Client
        x.prefix = "Mr."
        x.name = "John Smith"

        Client.printPrefix = False
        x.PrintName()
    End Sub
End Module
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-11-4 22:30:01
| Show all posts
Public, protected, friend, and private define the access rights of members in the class.

Other members, subclasses, instances, and friends of the public class can all be accessed
Other members of the protected class, subclasses can access
Other members of the friend class, the friend class can visit
Other members in the private class can access

Shared declares that members are shared, which is equivalent to static (static) in c++, c#, and java, and cannot be accessed in the instance. It can only be accessed by type. And its value is shared. Can be modified. This point is completely different from const.
Reply

Use magic Report

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

Points Rules

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

Quick Reply To Top Return to the list