Click here to Skip to main content
16,004,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm a newer in c# so maybe my question will seem naive to some of you. I have a class named config with one string field named kye.

When I apply the GET property of the class, the property has to return one variable kye in different types (Int or bool or String).

I need to implement this with help of enum operator. Please,any idea how can I do this?
Posted

I think you need to go back a step or two, and look at what an enum actually is.

There is no "enum operator" in C# - an enum is a list of values and names for values.

I'm not quite sure what it is you are trying to use an enum for, but I suspect that you are barking up to wrong tree!
What are you trying to achieve, that you think this is a good solution?
 
Share this answer
 
You mean something like this?

C#
public enum RetType {RetInt, RetBool, RetString};
...
public object PolimorphProperty(string key, RetType how) 
{
    get 
    { 
       switch (how)
       {
           case RetType.RetInt:
              ...;
           case RetType.RetBool:
              ...;
           case RetType.RetString:
              ...;
       }
    }
}


You can return object, but this won't help you, since on caller side you will need to cast it back anyway. You need to know on caller side what type you expect.

You should implement three different getter methods instead.
 
Share this answer
 
Comments
Mich_90 15-Jul-12 8:47am    
Zoltán,I can i can define the return type as generic instad of object.

public T PolimorphProperty<t>(string key, T how)
{
//todo
}
Zoltán Zörgő 15-Jul-12 8:52am    
This can be a good approach. See: http://msdn.microsoft.com/en-us/library/twcad0zb(v=vs.100).aspx

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