나는이있어 windows(MainWindow,SecondWindow)
, 하나 class (ExampleClass)
에 ExampleClass
두 strings (Name,SecondName)
와 방법으로 messagebox
해야부터 텍스트가 들어있는 Name + SecondName
변수를.
난에서 일부 텍스트를 추가 할 수 있도록 MainWindow
하는 ExampleClass Name
오픈에서 텍스트 문자열 다음 SecondWindow
에 ExampleClass SecondName
문자열입니다. 그 후 MainWindow
버튼 을 클릭 messagebox
하고 두 문자열을 모두 제공해야합니다.
Name + SecondName
MainWindow :
ExampleClass SomeClass = new ExampleClass();
SomeClass.Name = MainWindowTxtBox.Text;
두 번째 창 :
ExampleClass SomeClass = new ExampleClass();
SomeClass.SecondName = SecondWindowTxtBox.Text;
이것은 하나의 창에 대해서만 새로운 클래스의 istance를 생성합니다. 두 Windows 모두에 대한 istance를 생성 할 수 있습니까?
다음 static
과 같이 사용할 수 있습니다 .
class ExampleClass
{
public static string Name { get; set; }
public static string SecondName { get; set; }
public static void print()
{
MessageBox.Show(Name + SecondName);
}
}
그런 다음 MainWindow
:
ExampleClass.Name = MainWindowTxtBox.Text;
그리고 SecondWindow
:
ExampleClass.SecondName = SecondWindowTxtBox.Text;
그리고 마지막으로:
ExampleClass.print();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다