Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create aliases in c#

Tags:

c#

aliases

How do i create aliases in c#

Take this scenario

class CommandMessages
{
   string IDS_SPEC1_COMPONENT1_MODULE1_STRING1;
}

say i create an object of this class

CommandMessages objCommandMessage = new CommandMessages();

To i need to write lengthy string

objCommandMessage.IDS_SPEC1_COMPONENT1_MODULE1_STRING1 

every time i access the variable, this is a pain as i am using this variable as a key for a dictionary.

Dict[objCommandMessage.IDS_SPEC1_COMPONENT1_MODULE1_STRING1]

therefore i should be able to do something like this

Dict[str1]

where str1 is alias for objCommandMessage.IDS_SPEC1_COMPONENT1_MODULE1_STRING1, How do i do it?

like image 933
Gaddigesh Avatar asked Dec 18 '22 01:12

Gaddigesh


2 Answers

Create another, shorter, property that references the original one?

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 you like:

Dict[objCommandMessage.Str1]
like image 99
Andy Shellam Avatar answered Dec 24 '22 01:12

Andy Shellam


string str1 = objCommandMessage.IDS_SPEC1_COMPONENT1_MODULE1_STRING1;
like image 21
Rob Fonseca-Ensor Avatar answered Dec 24 '22 00:12

Rob Fonseca-Ensor