Почему методы set свойства и методы считывания сталкиваются с get_X и set_X методами?

Ваш ответ близок, но это может сработать лучше:

find -regex 'regex' -exec zip filname.zip {} +

Это поместит все соответствующие файлы в один zip-файл с именем filename.zip. Вам не нужно беспокоиться о специальных символах в имени файла (например, обрыв строки), что вы бы сделали, если бы передали результаты.

6
задан Motti 20 May 2009 в 10:46
поделиться

4 ответа

For languages that don't have the concept of properties, such as J# (which may very well have influenced that design decision), it's still necessary to have a simple name to call them.

8
ответ дан 8 December 2019 в 12:22
поделиться

The Common Language Specification (CLS) requires the use of get_ and set_ methods in the IL (decorated with special bits) when implementing Properties. This is necessary so that different compilers (C#, managed C++, VB.NET, J#, IronPython, etc.) create interoperable bytecodes.

Thus underscores are not "legal" characters in the broader sense. They are not CLS-compliant and therefore should not be used in non-private interfaces.

Also, see this article about writing CLS-compliant code on the MSDN.

8
ответ дан 8 December 2019 в 12:22
поделиться

Because they may need to be called from external code.

2
ответ дан 8 December 2019 в 12:22
поделиться

Good question - most of the compiler-generated members (anonymous types and methods) use names that are guaranteed to not clash with any members in your class. I think this particular instance (as well as the generated names for event methods) is a case where Microsoft made a little bit of a mistake.

The only reason I can think of that would justify the decision is that Microsoft may have been hoping to allow other languages to call these methods that do not themselves have a "property" concept or syntax.

1
ответ дан 8 December 2019 в 12:22
поделиться
Другие вопросы по тегам:

Похожие вопросы: