I am able to change the datatype of a particular property of an object on the fly, but I am not super happy with my approach, as I know that the object I am going to use in my project has like two dozen properties in there.
What I attempted
class Program
{
static void Main(string[] args)
{
NammaClass nammaClass = new NammaClass();
List<NammaClass> listNamma = new List<NammaClass>
{
new NammaClass{quant= 1, dattim = "01/01/2020"},
new NammaClass{quant= 2, dattim = "02/02/2022"}
};
var newList = (from user in listNamma
select new
{
quant = user.quant,//I Don't want to write this
dattim = DateTime.Parse(user.dattim)
}).ToList();
}
}
public class NammaClass
{
public int quant;
public string dattim;
}
The problem with above approach is that I am forced to use all the properties of the NammaClass object just to be able to change the datatype of one property, is there an elegant way to have the whole object but just one property's datatype changed.