Is it possible to clone a ValueType?
I don't know, if I have totally misunderstood the question.
Are you trying to do this?
public static void Main()
{
List<ValueType> values = new List<ValueType> {3, DateTime.Now, 23.4M};
DuplicateLastItem(values);
Console.WriteLine(values[2]);
Console.WriteLine(values[3]);
values[3] = 20;
Console.WriteLine(values[2]);
Console.WriteLine(values[3]);
}
static void DuplicateLastItem(List<ValueType> values2)
{
values2.Add(values2[values2.Count - 1]);
}
Every assignment of a valuetype is by definition a clone.
Edit:
When boxing a valuetype a copy of your valuetype will be contained in an instance of a ReferenceType.
Depending of the Cloning method, I don't foresee any differences.
You can use a hack using Convert.ChangeType
:
object x = 1;
var type = x.GetType();
var clone = Convert.ChangeType(x, type);
// Make sure it works
Assert.AreNotSame(x, clone);
The result is copy of the value boxed in new object.