C# 使用对象类型可避免数据转换

C# 使用对象类型可避免数据转换,c#,C#,如果我对属性类使用对象类型,是否会出现性能问题?而不是用数据类型单独分配它们并逐个转换它们。我使用对象来避免转换并提高性能。还是我做错了?请引导我。谢谢 DataSet ds = new DataSet(); List<DynamicData> details = new List<DynamicData>(); Queries qr = new Queries(); ds = qr.GetCacheableSP(); foreach (DataRow dtrow in

如果我对属性类使用对象类型,是否会出现性能问题?而不是用数据类型单独分配它们并逐个转换它们。我使用对象来避免转换并提高性能。还是我做错了?请引导我。谢谢

DataSet ds = new DataSet();

List<DynamicData> details = new List<DynamicData>();
Queries qr = new Queries();
ds = qr.GetCacheableSP();
foreach (DataRow dtrow in ds.Tables[0].Rows)
{

            DynamicData tbl_roads_avg_roughness = new DynamicData();

            tbl_roads_avg_roughness.site_category_func_class = dtrow["site_category_func_class"];
            tbl_roads_avg_roughness.csurvey_with_data = (dtrow["csurvey_with_data"]);
            tbl_roads_avg_roughness.ctotal_length = (dtrow["ctotal_length"]);
            tbl_roads_avg_roughness.caverage_iri = (dtrow["caverage_iri"]);
            tbl_roads_avg_roughness.date_imported = dtrow["date_imported"];
            tbl_roads_avg_roughness.color = dtrow["color"];
            tbl_roads_avg_roughness.csurvey_with_data_total = (dtrow["csurvey_with_data_total"]); ;
            tbl_roads_avg_roughness.ctotal_length_total = (dtrow["ctotal_length_total"]);

            tbl_roads_avg_roughness.tbl_roads_avg_roughness_access = true;
            details.Add(tbl_roads_avg_roughness);
    }
return details.ToArray();

public class DynamicData
{
    public object site_category_func_class { get; set; }
    public object csurvey_with_data { get; set; }
    public object ctotal_length { get; set; }
    public object caverage_iri { get; set; }
    public object date_imported { get; set; }
    public object color { get; set; }
    public object csurvey_with_data_total { get; set; }
    public object ctotal_length_total { get; set; }
    public object tbl_roads_avg_roughness_access { get; set; }
}
DataSet ds=新数据集();
列表详细信息=新列表();
查询qr=新查询();
ds=qr.GetCacheableSP();
foreach(ds.Tables[0].行中的DataRow dtrow)
{
DynamicData tbl_道路平均粗糙度=新DynamicData();
tbl_道路平均粗糙度。场地类别功能等级=dtrow[“场地类别功能等级”];
tbl_道路平均粗糙度.csurvey_与_数据=(dtrow[“csurvey_与_数据”);
tbl_道路平均粗糙度.ctotal_长度=(dtrow[“ctotal_长度]);
tbl_道路平均粗糙度。凹坑面积=凹坑面积(dtrow[“凹坑面积”);
tbl_道路平均粗糙度。导入日期=dtrow[“导入日期”];
tbl_道路平均粗糙度.color=dtrow[“color”];
tbl_道路平均粗糙度.csurvey_和数据总量=(dtrow[“csurvey_和数据总量]);
tbl_道路平均粗糙度.ctotal_长度总计=(dtrow[“ctotal_长度总计]);
tbl_道路平均粗糙度。tbl_道路平均粗糙度=真;
详细信息。添加(待定道路平均粗糙度);
}
返回详细信息。ToArray();
公共类动态CDATA
{
公共对象站点\类别\函数\类{get;set;}
公共对象csurvey_与_数据{get;set;}
公共对象ctotal_长度{get;set;}
公共对象caverage_iri{get;set;}
公共对象日期_导入{get;set;}
公共对象颜色{get;set;}
公共对象csurvey_与_data_total{get;set;}
公共对象ctotal_length_total{get;set;}
公共对象tbl_roads_avg_糙率_access{get;set;}
}

这是过早的优化。强类型不会比处理动态/对象类型产生更多的开销

随着应用程序的发展,你正在牺牲编译时检查、智能感知和基本上C#提供的所有语言功能的安全网


如果强类型(或序列化)让您如此困扰,请使用函数式语言,甚至使用node.js。

这是完全错误的。您能解释一下原因吗?JSON序列化程序可能会将它们解除装箱。我将把它们传递到客户端脚本中,并在这方面做一些操作。所以如果我用同样的代码可以吗?或者指定特定的数据类型?这是过早的优化。强类型不会比处理动态/对象类型产生更多的开销。随着应用程序的发展,你正在牺牲编译时检查、智能感知和基本上C#提供的所有语言功能的安全网。如果强类型(或序列化)让您如此困扰,请使用函数式语言,甚至使用node.js。