解决方案 »
- [求救]VS2005一新建ASP.NET 项目就关闭。报错信息如下
- 编写一个评分统计程序,共8个评委打分,统计时,去掉一个最高分和一个最低分,其余6个分数的平均分就是最后得分,程序最后应该显示这个得分,显示精度为1位整数2位小数
- HTML模板 谢谢了 深夜求救
- 视频通过av输出到电视机
- C# winForm编程 菜鸟级问题
- 关于在web.config中smtp的设置对邮件发送的影响的疑问
- 如何将整个XML文件加密?而不是只加密当中的元素值.
- webbrowser控件中使用session的问题,谢谢
- can't access class
- WebControls中的treeview对象不能用?
- C#中double型如何转成int型,小数部分四舍五入到整数?
- WinFrom 实现一个TreeView节点的提示效果
嗯,我放上完整代码吧。
public class CommonDataDetailModel
{
public DateTime DataTime { get; set; }
public decimal? AvgValue { get; set; }
public decimal? MinValue { get; set; }
public decimal? MaxValue { get; set; }
public decimal? TotalValue { get; set; }
public decimal? OverPercent { get; set; }
}public class HourData : CommonDataDetailModel
{
public decimal HourDataId { get; set; }
public DateTime DataTime { get; set; } }
public string PolNo { get; set; }
public decimal? AvgValue { get; set; }
public decimal? MinValue { get; set; }
public decimal? MaxValue { get; set; }
public decimal? TotalValue { get; set; }
public decimal? OverPercent { get; set; }
}
public class DataEntityConverter
{
public static object Convert(List<Models.CommonDataDetailModel> entities)
{ return obj; }
} public class Test
{
HourData hourDatas = new HourData();
DataEntityConverter.Convert(hourDatas); //这里报错
}
错误是:错误 9 与“EnterpriseTool.DataEntityConverter.Convert(System.Collections.Generic.List<Models.CommonDataDetailModel>)”最匹配的重载方法具有一些无效参数 E:\EnterpriseTool\app\HourData\MinData.cs 12 53 EnterpriseTool
最后一段没有复制全public class CommonDataDetailModel
{
public DateTime DataTime { get; set; }
public decimal? AvgValue { get; set; }
public decimal? MinValue { get; set; }
public decimal? MaxValue { get; set; }
public decimal? TotalValue { get; set; }
public decimal? OverPercent { get; set; }
}public class HourData : CommonDataDetailModel
{
public decimal HourDataId { get; set; }
public DateTime DataTime { get; set; } }
public string PolNo { get; set; }
public decimal? AvgValue { get; set; }
public decimal? MinValue { get; set; }
public decimal? MaxValue { get; set; }
public decimal? TotalValue { get; set; }
public decimal? OverPercent { get; set; }
}
public class DataEntityConverter
{
public static object Convert(List<Models.CommonDataDetailModel> entities)
{ return obj; }
} public class Test
{
void t()
{
HourData hourDatas = new HourData();
DataEntityConverter.Convert(hourDatas); //这里报错
}
}
public static object Convert(List<Models.CommonDataDetailModel> entities)
{ return obj; }
参数不对的,list<T> 你传的对象...
public class HourData : CommonDataDetailModel 既然是继承了 HourData 还需要写子类和父类共有的属性吗,那继承干什么..
嗯,谢谢指教,改过来了。
请问一下为什么普通用对象可以这样写,加上List就不行了呢?
如:using System;
using System.Collections.Generic;public class MyClass
{
public static void RunSnippet()
{
单车 bike = new 单车();
bike.轮子个数 = "100";
检测类.检测车辆轮子数(bike);
}
public class 车
{
public string 轮子个数{get; set;}
}
public class 单车: 车
{
public string 是否可以变速 {get; set;}
}
public class 汽车: 车
{
public string 自动挡还是手动挡{get;set;}
}
public class 检测类
{
public static void 检测车辆轮子数(车 obj){
Console.Write(obj.轮子个数);
}
}
}这样可以。下面的代码报错:public class MyClass
{
public static void RunSnippet()
{
List<单车> list = new List<单车>();
检测类.检测车辆轮子数(list);
}
public class 车
{
public string 轮子个数{get; set;}
}
public class 单车: 车
{
public string 是否可以变速 {get; set;}
}
public class 汽车: 车
{
public string 自动挡还是手动挡{get;set;}
}
public class 检测类
{
public static void 检测车辆轮子数(List<车> objs){
foreach(车 obj in objs){
Console.WriteLine(obj.轮子个数);
}
}
}
{
//DO SOMETHING HERE
}//调用时public void TestFunction()
{
List<单车> list=new List<单车>();
GList<单车>(list);
}你可以把T理解为是另一种形式的object类型,是类模板。可以代替任何一种类型
where后是对T的约束,这里写了一个 车 的约束,代表所传入的参数类型必须是车这个类或者是其子类型
{
public static void 检测车辆轮子数<T>(List<T> objs) where T : 车
{
foreach (车 obj in objs)
{
Console.WriteLine(obj.轮子个数);
}
} }检测类.检测车辆轮子数<单车>(new List<单车>());
检测类.检测车辆轮子数(bike);这样应该行把
检测类.检测车辆轮子数((车)bike);转换一下参数的类型