我有如下创建的自定义类型
public class FileTypeData
{
//AAAL ;Indicator;EMA7;1;1
public static List<FileTypeData> Data = new List<FileTypeData>();
public string Symbol { get; set; }
public string Catogery { get; set; }
public string Indicator { get; set; }
public string Signal { get; set; }
public int Buy { get; set; }
public int Hold { get; set; }
public int Sell { get; set; }
public int Wait { get; set; }
}
我定义了三个自定义类型列表,并尝试从中选择所有数据,如下所示:
var result = from Daily in CandelDataDaily
from Weekly in CandelDataWeekly
from Monthly in CandelDataMonthly
select new
{
d=Daily.Indicator,
w=Weekly.Indicator,
m= Monthly.Indicator
};
当三个列表有数据时它工作正常,但如果其中一个有帐号= 0表示没有数据结果返回为空,则出现问题,我想选择没有任何连接的所有数据,没有任何条件,因此没有任何数据
预期结果:
Daily Weekly Monthly
xx yy
zz ss mm
dd rr
由于
答案 0 :(得分:0)
我在没有linq的情况下解决了它,因为它不能给我我想要的外部或两者。 我的解决方案:`int TotalCount = CandelDataDaily.Count + CandelDataWeekly.Count + CandelDataMonthly.Count; int D_count = CandelDataDaily.Count; int W_count = CandelDataWeekly.Count; int M_count = CandelDataMonthly.Count;
for (int i = 0; i < TotalCount; i++)
{
if (D_count == 0 && W_count == 0 && M_count == 0) break;
if (D_count == 0) Data.Append("N/A").Append(";");
else { Data.Append(CandelDataDaily[i].Indicator).Append(";"); D_count--; }
if (W_count == 0) Data.Append("N/A").Append(";");
else { Data.Append(CandelDataWeekly[i].Indicator).Append(";"); W_count--; }
if (M_count == 0) Data.Append("N/A").Append(Environment.NewLine);
else { Data.Append(CandelDataMonthly[i].Indicator).Append(Environment.NewLine); ; M_count--; }
}`