---
title: "Polymorphism on c# property"  
description: "Polymorphism on c# property"  
author: "Anonymous User"  
published: 2014-08-28  
updated: 2014-08-28  
canonical: https://www.mindstick.com/forum/2181/polymorphism-on-c-sharp-property  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Polymorphism on c# property

I have a [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) 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](https://www.mindstick.com/articles/1527/string-split-in-c-sharp), MyItem, or List<MyItem>. I also want it so that when [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) consumes this class, accessing "FieldValue" returns the [right](https://www.mindstick.com/articles/12766/check-whether-you-are-doing-digital-transformation-right-or-not) type of object. Is there a way to do this? I'm not too clear on [generics](https://www.mindstick.com/articles/12420/generics-in-c-sharp-with-example), but there seems to be a way to do this using that.

## Replies

### Reply by Sumit Kesarwani

Hi jay, try this:

```
public class ItemField<T> where T :  ICloneable, IConvertible,
IComparable<string>, IEnumerable<char>, IEnumerable,
IEquatable<string>{    public string FieldName { get; set; }    public T FieldValue { get; set; }}
```


---

Original Source: https://www.mindstick.com/forum/2181/polymorphism-on-c-sharp-property

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
