无法隐式转换类型'System.Collections.Generic.List [英] Cannot implicitly convert type 'System.Collections.Generic.List
问题描述
public List< spectruminfo> GetSpectrumBandList(uint StartTime)
{
List< spectruminfo> splist = new List< spectruminfo>();
using(System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DbApi.ConnectionString) )
{
conn.Open();
var spectrumItems = DbApi.GetSpectrumBandStartValue(conn,StartTime);
foreach(SpectrumItems中的SpectrumItem项目)
{
SpectrumInfo spinfo = new SpectrumInfo();
spinfo.StartTime = item.startTime;
spinfo.BandStart = item.bandStart;
spinfo.PathId = item.pathId;
spinfo。 CellId = item.cellid;
splist.Add(spinfo);
}
}
返回splist;
}
var spectrumBandList = GetSpectrumBandList((uint)StartTime);
//matchInfo.Channels = new List < int > 跨度>();
matchInfo.Channels = spectrumBandList;
无法隐式转换类型'System.Collections.Generic.List < ProView.Web。 Services.SpectrumInfo > 'to'System.Collections.Generic.List < < span class =code-leadattribute> int > '
我得到错误(matchInfo.Channels = spectrumBandList;)。如何解决这个问题
matchInfo.Channels的类型是什么。
如果它的类型是List< int>那么你就不能为它指定spectrumBandList。
你必须定义matchInfo。频道为列表< spectruminfo>。
认真?
它告诉你究竟是什么问题是。
matchInfo.Channels的类型为System.Collections.Generic.List< int>你给它分配了一个值System.Collections.Generic.List< ProView.Web.Services.SpectrumInfo>
你需要设置一个不同的列表。
这是因为函数GetSpectrumBandList()
返回一个包含splist
的列表一个的列表SpectrumInfo
ProView.Web.Services.SpectrumInfo这不能分配给整数列表,这就是你得到这样的错误的原因。你可以通过这样使用来避免这种情况:
matchInfo.Channels = new List< spectruminfo>(); < / spectruminfo > 跨度>
public List<spectruminfo> GetSpectrumBandList(uint StartTime)
{
List<spectruminfo> splist = new List<spectruminfo>();
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DbApi.ConnectionString))
{
conn.Open();
var spectrumItems = DbApi.GetSpectrumBandStartValue(conn, StartTime);
foreach (SpectrumItem item in spectrumItems)
{
SpectrumInfo spinfo = new SpectrumInfo();
spinfo.StartTime = item.startTime;
spinfo.BandStart = item.bandStart;
spinfo.PathId = item.pathId;
spinfo.CellId = item.cellid;
splist.Add(spinfo);
}
}
return splist;
}
var spectrumBandList = GetSpectrumBandList((uint)StartTime);
//matchInfo.Channels = new List<int>();
matchInfo.Channels = spectrumBandList;
Cannot implicitly convert type 'System.Collections.Generic.List<ProView.Web.Services.SpectrumInfo>' to 'System.Collections.Generic.List<int>'
I got error for (matchInfo.Channels = spectrumBandList;).how to solve this
What is the type of matchInfo.Channels.
If its type isList<int>then you cannot assign spectrumBandList to it.
You have to define matchInfo.Channels asList<spectruminfo>.
Seriously?
It tells you exactly what the problem is.
matchInfo.Channels is of type System.Collections.Generic.List<int> and you're assigning it a value of System.Collections.Generic.List<ProView.Web.Services.SpectrumInfo>
You need to set a different list.
this is because the functionGetSpectrumBandList()
returns a listsplist
that contains a list ofSpectrumInfo
ProView.Web.Services.SpectrumInfowhich cannot be assign to a list of integers that's why you are getting such error. you can avoid this by using like this :
matchInfo.Channels = new List<spectruminfo>();</spectruminfo>
这篇关于无法隐式转换类型'System.Collections.Generic.List的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!