Answer the question
In order to leave comments, you need to log in
Parameterized property in c# - how to set?
Duplicate preamble from my previous question .
To make it clear where this question comes from: after a long experience working on vb.net (as my first language), relatively recently I had the need, and most importantly, the ability to master c # (from version 7.0) At the same time, having experience with JavaScript , I didn’t have any particular difficulties with mastering the c# syntax. Of course, I still constantly draw analogies with vb.net, since I often miss a lot of its features, which are not supported in c# a priori. And now, I would like to ask experts about one such feature.
In vb.net, I can define and successfully use properties with parameters, and you can define parameterized properties not only in classes, but also in interfaces, while parameters can be declared optional. This is a very handy feature when you need to return (or set) a value for a property that depends on something.
Here is an example on vb.net:
'''<summary>Отрасль промышленности</summary>
Public NotInheritable Class Industry : Implements IEnum(Of Byte)
'''<summary>Код отраслевого направления</summary>
Public ReadOnly Property Code As Byte Implements IEnum(Of Byte).ID
'''<summary>Наименование отраслевого направления</summary>
'''<param name="Language">Язык, на котором следует вернуть наименование. Если язык не задан или он не поддерживается, то используется язык, назначенный в контекст текущего потока.</param>
Public ReadOnly Property Name(Optional language As Language = Nothing) As String Implements IEnum(Of Byte).Name
Get
Return ...
End Get
End Property
'и так далее...
End Class
Answer the question
In order to leave comments, you need to log in
I completely agree that there is more beautiful syntactic sugar in VB .NET. And the possibilities are the same, because everything eventually compiles into the same result.
As for properties with parameters... In C#, there is no such thing without dancing with a tambourine, but why not use a regular function?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question