Return Enum From C# Property getters

前端 未结 7 964
谎友^
谎友^ 2021-01-21 14:35

How do you return an Enum from a setter/getter function?

Currently I have this:

    public enum LowerCase
    {
        a,
        b,
    }
    public en         


        
7条回答
  •  耶瑟儿~
    2021-01-21 14:53

    The error is correct. It's basically the same as doing this

    public int ChooseCase
    {
        get{ return int; }
    }
    

    What you'll want to do is use real classes - not enums - with a common base.

    public abstract class Case
    {
        public abstract string ModifyString(string value);
    }
    
    public class UpperCase : Case
    {
        public override string ModifyString( string value )
        { 
            return String.ToUpper( value ); 
        }
    }
    

提交回复
热议问题