Click here to Skip to main content
15,895,880 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created several public class witnin a Public Static Class Constants. I created a new public class Location_Code but I cannot reference it.


public class LOCATION_CODE
           {
               public enum CODE
               {
                   AA, AC, AE, AF, AG, AJ, AL, AM, AN, AO, AQ, AR, AS, AT, AU, AV, AY, BA, BB, BC, BD, BE, BF,
                   BG, BH, BL, BM, BN, BO
               }
               public static string DISPLAY_STRING(CODE p)
               {
                   switch (p)
                   {
                       case CODE.AA: return "ARUBA (" + p.ToString() + ")";
                       case CODE.AC: return "ANTIGUA AND BARBUDA (" + p.ToString() + ")";
                       case CODE.AE: return "UNITED ARAB EMIRATES (" + p.ToString() + ")";
                       case CODE.AF: return "AFGHANISTAN (" + p.ToString() + ")";
                       case CODE.AG: return "ALGERIA (" + p.ToString() + ")";
                       case CODE.AJ: return "AZERBIAJAN (" + p.ToString() + ")";
                       case CODE.AL: return "ALBANIA (" + p.ToString() + ")";
                       case CODE.AM: return "ARMENIA (" + p.ToString() + ")";
                       case CODE.AN: return "ANDORRA (" + p.ToString() + ")";
                       case CODE.AO: return "ANGOLA (" + p.ToString() + ")";
                       case CODE.AQ: return "AMERICAN SAMOA (" + p.ToString() + ")";
                       case CODE.AR: return "ARGENTINA (" + p.ToString() + ")";
                       case CODE.AS: return "AUSTRALIA (" + p.ToString() + ")";
                       case CODE.AT: return "ASMORE AND CARTIER (" + p.ToString() + ")";
                       case CODE.AU: return "AUSTRIA (" + p.ToString() + ")";
                       case CODE.AV: return "ANGUILLA (" + p.ToString() + ")";
                       case CODE.AY: return "ANTARTICA (" + p.ToString() + ")";

                   }
                   return null;
               }


What I have tried:

I've committed changes.
I'm "using" the Namespace but still that class doesn't appear in the selection. I'd appreciate any ideas.
Posted
Updated 21-Nov-17 5:58am
Comments
PIEBALDconsult 21-Nov-17 12:07pm    
Without seeing more code, I can't really help with that, but I recommend redesigning the code.
What I prefer (and it may just be me), is to decorate each enum member with a DescriptionAttribute:

public enum CODE
{
[System.ComponentModel.DescriptionAttribute("ARUBA (AA)")]
AA, ...

Then, at runtime, I read the members and their descriptions into a Dictionary<CODE,string>
Member 13481361 21-Nov-17 12:24pm    
I like the idea of reading members into a Dictionary.

LOCATION_CODE is not the same namespace. Constants is the namespace. But even if I type Constants.LOCATION_CODE (LOCATION_CODE does not appear in the menu to select it.
So I can't create an instance of the class because it does not appear to exist.
So I can't create an

Assuming LOCATION_CODE is in the same namespace, or that you have used the correct using line, and also referenced the Assembly if it isn't the same one, then this code will work:
LOCATION_CODE lc = new LOCATION_CODE();
Or:
LOCATION_CODE.CODE code = LOCATION_CODE.CODE.AG;
Console.WriteLine(LOCATION_CODE.DISPLAY_STRING(code));

I wouldn't do it like that though: Human readable strings for enum elements[^] may help.
 
Share this answer
 
// to create an instance of the class
LOCATION_CODE lc = new LOCATION_CODE();

// if you want to use DISPLAY_STRING you don't use an instance
// as it is static so you call it from the type
string code = LOCATION_CODE.DISPLAY_STRING(LOCATION_CODE.CODE.AA);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900