private와public 키워드 대상에 대한 접근 권한 문제
8328 단어 private
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 }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Java 프로그래밍 : 객체지향 (2)default : 같은 패키지 내 공개 하지만 게터 메소드(getter methods)와 세터 메소드(setter method)를 사용하면 비공개 필드에 우회적으로 접근해 private 필드를 반환(get) 하거나 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.