Why do I get Error “The type ‘string’ must be a non-nullable value type in order to use it as parameter ‘T’ in the generic type or method ‘System.Nullable'”?
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using Universe;
namespace Universe
{
public class clsdictionary
{
private string? m_Word = "";
private string? m_Meaning = "";
string? Word {
get { return m_Word; }
set { m_Word = value; }
}
string? Meaning {
get { return m_Meaning; }
set { m_Meaning = value; }
}
}
}
Use
stringinstead ofstring?in all places in your code.The
Nullable<T>type requires that T is a non-nullable value type, for exampleintorDateTime. Reference types likestringcan already be null. There would be no point in allowing things likeNullable<string>so it is disallowed.Also if you are using C# 3.0 or later you can simplify your code by using auto-implemented properties: