How can we create parameterized properties in C #

How to create parameterized properties in C #.

public readonly string ConnectionString(string ConnectionName) { get { return System.Configuration.ConfigurationManager.ConnectionStrings[ConnectionName].ToString(); } } 
+4
source share
2 answers

The only type of parameterized property you can create in C # is the indexer property:

 public class MyConnectionStrings { private string GetConnectionString(string connectionName) { ... } public string this[string connectionName] { get { return GetConnectionString(connectionName); } } } 

Otherwise, just create a method - it looks like what you are looking for.

+14
source

C # 4 allows this , but only to access external COM properties.

0
source

Source: https://habr.com/ru/post/1309073/


All Articles