簡體   English   中英

如何從作為列表數組的對象成員中的值分配給另一個對象成員

[英]how to assign values from an object member which is a list array to another object member

我在這里定義了兩個類:

public class datatype1
{
    public double lat { get; set; }
    public double lon { get; set; }
}
public class datatype2
{
    public List<List<double>> lat { get; set; }
    public List<List<double>> lon { get; set; }
}

var data1=new datatype1();
var data2=new datatype2();
data2.lat[0][0]=30.0;
data2.lat[1][0]=40.0;
data2.lon[0][0]=30.0;
data2.lon[1][0]=40.0;

如何在循環中將data2中的值分配給data1

原始數據來自以下兩個鏈接:

1) ftp://ftp.star.nesdis.noaa.gov/pub/smcd/spb/xjin/icvs/json/npp/2016/20160103_CRIS.SDR.json

此代碼使用http://json2csharp.com/返回一個類似於datatype1的json類型:

public class RootObject
{
    public double lat { get; set; }
    public double lon { get; set; }
    public int BT900 { get; set; }
    public int BT2500 { get; set; }
    public int BT1030 { get; set; }
    public int BT1500 { get; set; }
    public double iRad900 { get; set; }
    public double iRad2500 { get; set; }
    public int OverallQFlw { get; set; }
    public int OverallQFmw { get; set; }
    public int OverallQFsw { get; set; }
    public int FOV { get; set; }
    public int FOR { get; set; }
    public int Scan { get; set; }
    public int QF11 { get; set; }
    public int QF12 { get; set; }
    public int QF13 { get; set; }
    public int QF14 { get; set; }
    public int QF15 { get; set; }
    public int QF16 { get; set; }
    public int QF2lw { get; set; }
    public int QF2mw { get; set; }
    public int QF2sw { get; set; }
    public int QF32lw { get; set; }
    public int QF32mw { get; set; }
    public int QF32sw { get; set; }
    public int QF33lw { get; set; }
    public int QF33mw { get; set; }
    public int QF33sw { get; set; }
    public int QF34lw { get; set; }
    public int QF34mw { get; set; }
    public int QF34sw { get; set; }
    public int QF35lw { get; set; }
    public int QF35mw { get; set; }
    public int QF35sw { get; set; }
    public int QF41lw { get; set; }
    public int QF41mw { get; set; }
    public int QF41sw { get; set; }
    public int QF42lw { get; set; }
    public int QF42mw { get; set; }
    public int QF42sw { get; set; }
    public int QF43lw { get; set; }
    public int QF43mw { get; set; }
    public int QF43sw { get; set; }
    public int QF44lw { get; set; }
    public int QF44mw { get; set; }
    public int QF44sw { get; set; }
    public int QF45lw { get; set; }
    public int QF45mw { get; set; }
    public int QF45sw { get; set; }
    public int DSWSizeForwardLw { get; set; }
    public int DSWSizeForwardMw { get; set; }
    public int DSWSizeForwardSw { get; set; }
    public int DSWSizeReverseLw { get; set; }
    public int DSWSizeReverseMw { get; set; }
    public int DSWSizeReverseSw { get; set; }
    public int ITWSizeForwardLw { get; set; }
    public int ITWSizeForwardMw { get; set; }
    public int ITWSizeForwardSw { get; set; }
    public int ITWSizeReverseLw { get; set; }
    public int ITWSizeReverseMw { get; set; }
    public int ITWSizeReverseSw { get; set; }
    public int PRTTempsForward { get; set; }
    public int PRTTempsReverse { get; set; }
    public int ImpulseNoiselw { get; set; }
    public int ImpulseNoisemw { get; set; }
    public int ImpulseNoisesw { get; set; }
    public int ZPDFClw { get; set; }
    public int ZPDFCmw { get; set; }
    public int ZPDFCsw { get; set; }
    public int SDRFClw { get; set; }
    public int SDRFCmw { get; set; }
    public int SDRFCsw { get; set; }
    public int ZPDMglw { get; set; }
    public int ZPDMgmw { get; set; }
    public int ZPDMgsw { get; set; }
    public double DSSymmetrylw { get; set; }
    public double DSSymmetrymw { get; set; }
    public double DSSymmetrysw { get; set; }
    public double DSSpcStabForwardlw { get; set; }
    public double DSSpcStabForwardmw { get; set; }
    public double DSSpcStabForwardsw { get; set; }
    public double DSSpcStabReverselw { get; set; }
    public double DSSpcStabReversemw { get; set; }
    public double DSSpcStabReversesw { get; set; }
    public double ITSpcStabForwardlw { get; set; }
    public double ITSpcStabForwardmw { get; set; }
    public double ITSpcStabForwardsw { get; set; }
    public double ITSpcStabReverselw { get; set; }
    public double ITSpcStabReversemw { get; set; }
    public double ITSpcStabReversesw { get; set; }
    public double ITTempStabForward { get; set; }
    public double ITTempStabReverse { get; set; }
    public double ITTempCons { get; set; }
    public double MeaLaserWL { get; set; }
    public double MonLaserWL { get; set; }
    public double ResLaserWL { get; set; }
    public string Maneuver { get; set; }
    public string V { get; set; }
    public string granuleID { get; set; }
}

此代碼使用http://json2csharp.com/返回一個類似於datatype2的json類型。

2) ftp://ftp.star.nesdis.noaa.gov/pub/smcd/spb/xjin/icvs/json/npp/2016/20160104_CRIS.SDR.json

public class RootObject
{
    public List<List<double>> lat { get; set; }
    public List<List<double>> lon { get; set; }
    public List<List<int>> BT900 { get; set; }
    public List<List<int>> BT2500 { get; set; }
    public List<List<int>> BT1030 { get; set; }
    public List<List<int>> BT1500 { get; set; }
    public List<List<double>> iRad900 { get; set; }
    public List<List<double>> iRad2500 { get; set; }
    public List<List<int>> OverallQFlw { get; set; }
    public List<List<int>> OverallQFmw { get; set; }
    public List<List<int>> OverallQFsw { get; set; }
    public List<List<int>> FOV { get; set; }
    public List<List<int>> FOR { get; set; }
    public List<List<int>> Scan { get; set; }
    public List<List<int>> QF11 { get; set; }
    public List<List<int>> QF12 { get; set; }
    public List<List<int>> QF13 { get; set; }
    public List<List<int>> QF14 { get; set; }
    public List<List<int>> QF15 { get; set; }
    public List<List<int>> QF16 { get; set; }
    public List<List<int>> QF2lw { get; set; }
    public List<List<int>> QF2mw { get; set; }
    public List<List<int>> QF2sw { get; set; }
    public List<List<int>> QF32lw { get; set; }
    public List<List<int>> QF32mw { get; set; }
    public List<List<int>> QF32sw { get; set; }
    public List<List<int>> QF33lw { get; set; }
    public List<List<int>> QF33mw { get; set; }
    public List<List<int>> QF33sw { get; set; }
    public List<List<int>> QF34lw { get; set; }
    public List<List<int>> QF34mw { get; set; }
    public List<List<int>> QF34sw { get; set; }
    public List<List<int>> QF35lw { get; set; }
    public List<List<int>> QF35mw { get; set; }
    public List<List<int>> QF35sw { get; set; }
    public List<List<int>> QF41lw { get; set; }
    public List<List<int>> QF41mw { get; set; }
    public List<List<int>> QF41sw { get; set; }
    public List<List<int>> QF42lw { get; set; }
    public List<List<int>> QF42mw { get; set; }
    public List<List<int>> QF42sw { get; set; }
    public List<List<int>> QF43lw { get; set; }
    public List<List<int>> QF43mw { get; set; }
    public List<List<int>> QF43sw { get; set; }
    public List<List<int>> QF44lw { get; set; }
    public List<List<int>> QF44mw { get; set; }
    public List<List<int>> QF44sw { get; set; }
    public List<List<int>> QF45lw { get; set; }
    public List<List<int>> QF45mw { get; set; }
    public List<List<int>> QF45sw { get; set; }
    public List<List<int>> DSWSizeForwardLw { get; set; }
    public List<List<int>> DSWSizeForwardMw { get; set; }
    public List<List<int>> DSWSizeForwardSw { get; set; }
    public List<List<int>> DSWSizeReverseLw { get; set; }
    public List<List<int>> DSWSizeReverseMw { get; set; }
    public List<List<int>> DSWSizeReverseSw { get; set; }
    public List<List<int>> ITWSizeForwardLw { get; set; }
    public List<List<int>> ITWSizeForwardMw { get; set; }
    public List<List<int>> ITWSizeForwardSw { get; set; }
    public List<List<int>> ITWSizeReverseLw { get; set; }
    public List<List<int>> ITWSizeReverseMw { get; set; }
    public List<List<int>> ITWSizeReverseSw { get; set; }
    public List<List<int>> PRTTempsForward { get; set; }
    public List<List<int>> PRTTempsReverse { get; set; }
    public List<List<int>> ImpulseNoiselw { get; set; }
    public List<List<int>> ImpulseNoisemw { get; set; }
    public List<List<int>> ImpulseNoisesw { get; set; }
    public List<List<int>> ZPDFClw { get; set; }
    public List<List<int>> ZPDFCmw { get; set; }
    public List<List<int>> ZPDFCsw { get; set; }
    public List<List<int>> SDRFClw { get; set; }
    public List<List<int>> SDRFCmw { get; set; }
    public List<List<int>> SDRFCsw { get; set; }
    public List<List<int>> ZPDMglw { get; set; }
    public List<List<int>> ZPDMgmw { get; set; }
    public List<List<int>> ZPDMgsw { get; set; }
    public List<List<double>> DSSymmetrylw { get; set; }
    public List<List<double>> DSSymmetrymw { get; set; }
    public List<List<double>> DSSymmetrysw { get; set; }
    public List<List<double>> DSSpcStabForwardlw { get; set; }
    public List<List<double>> DSSpcStabForwardmw { get; set; }
    public List<List<double>> DSSpcStabForwardsw { get; set; }
    public List<List<double>> DSSpcStabReverselw { get; set; }
    public List<List<double>> DSSpcStabReversemw { get; set; }
    public List<List<double>> DSSpcStabReversesw { get; set; }
    public List<List<double>> ITSpcStabForwardlw { get; set; }
    public List<List<double>> ITSpcStabForwardmw { get; set; }
    public List<List<double>> ITSpcStabForwardsw { get; set; }
    public List<List<double>> ITSpcStabReverselw { get; set; }
    public List<List<double>> ITSpcStabReversemw { get; set; }
    public List<List<double>> ITSpcStabReversesw { get; set; }
    public List<List<double>> ITTempStabForward { get; set; }
    public List<List<double>> ITTempStabReverse { get; set; }
    public List<List<double>> ITTempCons { get; set; }
    public List<List<double>> MeaLaserWL { get; set; }
    public List<List<double>> MonLaserWL { get; set; }
    public List<List<double>> ResLaserWL { get; set; }
    public List<string> Maneuver { get; set; }
    public List<string> V { get; set; }
    public List<string> granuleID { get; set; }
}

在這種情況下,返回的對象的每個屬性包含11個元素。

如何每個屬性的第一要素分配中datatype2使用foreach循環datatype1?

datatype2 data2 = GetYourJsonData();
for(var i=0; i<data2.lat.Count; i++)
{
    datatype1 data1 = new datatype1 
        {
            lat = data2.lat[i][0],
            lon = data.lon[i][0] // remember check for nulls
        };

       // do your stuff with data1
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM