How to create aliases in C #

How to create aliases in C #

Take this script

class CommandMessages { string IDS_SPEC1_COMPONENT1_MODULE1_STRING1; } 

say I create an object of this class

 CommandMessages objCommandMessage = new CommandMessages(); 

I need to write a long string

 objCommandMessage.IDS_SPEC1_COMPONENT1_MODULE1_STRING1 

every time I access a variable, it’s a pain since I use this variable as a key for a dictionary.

 Dict[objCommandMessage.IDS_SPEC1_COMPONENT1_MODULE1_STRING1] 

so I would have to do something like this

 Dict[str1] 

where str1 is an alias for objCommandMessage.IDS_SPEC1_COMPONENT1_MODULE1_STRING1, How do I do this?

+4
source share
3 answers

Create another, shorter property that references the original?

 class CommandMessages { string IDS_SPEC1_COMPONENT1_MODULE1_STRING1; public string Str1 { get { return this.IDS_SPEC1_COMPONENT1_MODULE1_STRING1; } } } 

Then you can use the following anywhere:

 Dict[objCommandMessage.Str1] 
+7
source
 string str1 = objCommandMessage.IDS_SPEC1_COMPONENT1_MODULE1_STRING1; 
+3
source
 public string str1 { get { return objCommandMessage.IDS_SPEC1_COMPONENT1_MODULE1_STRING1; } } 
+2
source

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


All Articles