Click here to Skip to main content
15,889,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
}

XML
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
Posted

What is the type of matchInfo.Channels.
If its type is
C#
List<int>
then you cannot assign spectrumBandList to it.
You have to define matchInfo.Channels as
C#
List<spectruminfo>
.
 
Share this answer
 
v2
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.
 
Share this answer
 
this is because the function GetSpectrumBandList() returns a list splist that contains a list of SpectrumInfo

VB
ProView.Web.Services.SpectrumInfo
which cannot be assign to a list of integers that's why you are getting such error. you can avoid this by using like this :

VB
matchInfo.Channels = new List<spectruminfo>();</spectruminfo>
 
Share this answer
 
try..
C#
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);
//}
foreach (var 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;
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900