그래서 Class1은 Class2보다 먼저 호출됩니다. 클래스 1의 Sfile에 텍스트가 포함되어 있으며이를 확인했습니다. class2에서 사용하는 동안 그것은 null입니다. 나는 뭔가를 놓친다는 것을 알고, 단지 무엇을 기억할 수 없다. 감사!정적 변수 다른 클래스의 호출
public static Class1{
public static StreamWriter Sfile;
internal static void Function1(){
StreamWriter Sfile = new StreamWriter(str1, true);
Sfile.Write(Text)
}
}
public partial class Class2{
private void Function2(){
StreamWriter PrintField=Class1.Sfile;
//Sfile is null;
}
}
언어를 나타내는 태그를 추가하십시오. – arshajii
class1에'sfile'을 초기화하지 않았습니다. –
내부 함수 'Sfile = new StreamWriter (str1, true);'에서 이것을 사용하십시오! 그렇지 않으면 지역 변수를 선언하고 있습니다! – NINCOMPOOP