Почему я не могу объявить закрытый член локального типа файла в другом классе в том же файле? ⇐ C#
Почему я не могу объявить закрытый член локального типа файла в другом классе в том же файле?
This code:
public class Class1 { private Class2 _class2; private void Something() { Class2 class2; } } file class Class2 { } produces compiler error CS9051 on the member _class2 but not on the local variable class2 inside the method:
File-local type 'Class2' cannot be used in a member signature in non-file-local type 'Class1'.
Clicking on the link provided with CS9051 opens this page, which at the time of this writing states Sorry, we don't have specifics on this C# error. I couldn't find anything else on the web which explains why this is the case. Can someone please explain why I can use Class2 inside of a method or property within Class1 but not as a private class member? It seems like this reduces the usefulness of an otherwise-useful feature (the file access modifier).
Источник: https://stackoverflow.com/questions/780 ... lass-withi
This code:
public class Class1 { private Class2 _class2; private void Something() { Class2 class2; } } file class Class2 { } produces compiler error CS9051 on the member _class2 but not on the local variable class2 inside the method:
File-local type 'Class2' cannot be used in a member signature in non-file-local type 'Class1'.
Clicking on the link provided with CS9051 opens this page, which at the time of this writing states Sorry, we don't have specifics on this C# error. I couldn't find anything else on the web which explains why this is the case. Can someone please explain why I can use Class2 inside of a method or property within Class1 but not as a private class member? It seems like this reduces the usefulness of an otherwise-useful feature (the file access modifier).
Источник: https://stackoverflow.com/questions/780 ... lass-withi
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Изменить CSS для всех элементов в том же классе при падении на одном элементе в том же классе
Anonymous » » в форуме CSS - 0 Ответы
- 4 Просмотры
-
Последнее сообщение Anonymous
-