Почему я не могу объявить закрытый член локального типа файла в другом классе в том же файле?C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Почему я не могу объявить закрытый член локального типа файла в другом классе в том же файле?

Сообщение Anonymous »


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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»