forum

Home / DeveloperSection / Forums / Polymorphism on c# property

Polymorphism on c# property

Anonymous User 1864 28-Aug-2014

I have a class like this:

public class ItemField
{
    public string FieldName { get; set; }
    public object FieldValue
    {
        get;
        set;
    }
}

I want to have it so that "FieldValue" can only be of type string, MyItem, or List<MyItem>. I also want it so that when code consumes this class, accessing "FieldValue" returns the right type of object. Is there a way to do this? I'm not too clear on generics, but there seems to be a way to do this using that.


c# c# 
Updated on 28-Aug-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By