How to convert this Java code in C# code?

Tags: , , ,



I tried to convert my Java code in C# but I missed something.

Java code

  public Map<String, MyDataClass> getData() {
        return data;
    }

    public void setDataCarriers(Map<String, MyDataClass> data) {
        this.data = data;
    }

Which is converted by tool like following:

public virtual IDictionary<string, MyDataClass> Data
        {
            get
            {
                return data;
            }
            set
            {
                this.data = value;
            }
        }

but getting error:

Using the generic type ‘MyDataClass’ requires 1 type arguments

Java code

public class MyDataClass<T> implements Serializable {

    private T demohere;

    public T get() {
        return demohere;
    }

    public void set(T demohere) {
        this.demohere= demohere;
    }
 }

Converted to C#

 [Serializable]
    public class MyDataClass<T>
    {
        private T demohere;
        
        public virtual T demohere
        {
            get
            {
                return demohere;
            }
            set
            {
                this.demohere= value;
            }
        }
    }

Answer

You should change type of Data to IDictionary<String, MyDataClass> and remove type argument <T> from MyDataClass



Source: stackoverflow