private와public 키워드 대상에 대한 접근 권한 문제

8328 단어 private
1. private 키워드의 접근 권한은 클래스 접근 권한입니다.static 키워드를 추가하면 클래스를 통해서만 접근할 수 있고, 그렇지 않으면 클래스의 대상을 통해서만 접근할 수 있습니다.
 1 using System;

 2 using System.Collections.Generic;

 3 using System.ComponentModel;

 4 using System.Data;

 5 using System.Drawing;

 6 using System.Linq;

 7 using System.Text;

 8 using System.Windows.Forms;

 9 

10 namespace Test

11 {

12 public partial class Form2 : Form

13 {

14 public string s1; 

15 private string s2;

16 private static string s3;

17 public Form2()

18 {

19 InitializeComponent();

20 }

21 

22 private void buttonSend_Click(object sender, EventArgs e)

23 {

24 s1 = textBox1.Text;

25 Form2 f2 = new Form2();

26 f2.s2 = "ab";// f2 s1 s2, s3

27 Form2.s3 = "abc";// Form2 s3

28 }

29 

30 private void Form2_Load(object sender, EventArgs e)

31 {

32 

33 }

34 }

35 }
 2.public 키워드는 형식과 형식 구성원의 접근 수식자입니다.공공 방문은 허용된 최고 방문 단계로 공공 구성원에 대한 접근에 제한이 없다.static 키워드를 추가하지 않으면 클래스 밖에서 대상을 통해 접근할 수 있고 static 키워드를 추가하면 클래스를 통해서만 접근할 수 있습니다.
 1 using System;

 2 using System.Collections.Generic;

 3 using System.ComponentModel;

 4 using System.Data;

 5 using System.Drawing;

 6 using System.Linq;

 7 using System.Text;

 8 using System.Windows.Forms;

 9 

10 namespace Test

11 {

12     public partial class Form1 : Form

13     {

14         

15         public Form1()

16         {

17             InitializeComponent();

18         }

19 

20         private void button1_Click(object sender, EventArgs e)

21         {

22             Form2 f2 = new Form2();

23             //f1.Owner = this;

24             f2.Show();

25             f2.s1 = "ab";

26             Form2.s11 = "a";

27         }

28     }

29 }

좋은 웹페이지 즐겨찾기