Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从字典中检索<;字符串,列表<;int>&燃气轮机; public Dictionary GetTotalLengt\u volumehof memberused\u AlongStaadName() { var memberData=新字典(); var sec_Dict=_sectionDetails.GetAllMemberIDsWithinATable(); 字符串_stdName=“”; double _memLength=0.0;double _totalMemLength=0.0; double _memVolume=0.0;double _totalMemVolume=0.0; foreach(sec_Dict.key中的字符串s) { foreach(以秒为单位的整数n) { _memLength=this.Getlengthofmember(n); _totalMemLength=_memLength+_totalMemLength; _memVolume=this.GetVolumeofmember(n); _totalMemVolume=\u memVolume+\u totalMemVolume; } } this.STAAD_NAME=\u stdName; this.TOTAL_MEMBER_LENGTH=_totalMemLength; this.TOTAL_MEMBER_VOLUME=_totalMemVolume; 列表=新列表(); 列表。添加(此。成员的总长度); 列表.添加(此.成员的总体积); memberData.Add(this.STAAD_NAME,list); 返回成员数据; }_C#_Dictionary - Fatal编程技术网

C# 如何从字典中检索<;字符串,列表<;int>&燃气轮机; public Dictionary GetTotalLengt\u volumehof memberused\u AlongStaadName() { var memberData=新字典(); var sec_Dict=_sectionDetails.GetAllMemberIDsWithinATable(); 字符串_stdName=“”; double _memLength=0.0;double _totalMemLength=0.0; double _memVolume=0.0;double _totalMemVolume=0.0; foreach(sec_Dict.key中的字符串s) { foreach(以秒为单位的整数n) { _memLength=this.Getlengthofmember(n); _totalMemLength=_memLength+_totalMemLength; _memVolume=this.GetVolumeofmember(n); _totalMemVolume=\u memVolume+\u totalMemVolume; } } this.STAAD_NAME=\u stdName; this.TOTAL_MEMBER_LENGTH=_totalMemLength; this.TOTAL_MEMBER_VOLUME=_totalMemVolume; 列表=新列表(); 列表。添加(此。成员的总长度); 列表.添加(此.成员的总体积); memberData.Add(this.STAAD_NAME,list); 返回成员数据; }

C# 如何从字典中检索<;字符串,列表<;int>&燃气轮机; public Dictionary GetTotalLengt\u volumehof memberused\u AlongStaadName() { var memberData=新字典(); var sec_Dict=_sectionDetails.GetAllMemberIDsWithinATable(); 字符串_stdName=“”; double _memLength=0.0;double _totalMemLength=0.0; double _memVolume=0.0;double _totalMemVolume=0.0; foreach(sec_Dict.key中的字符串s) { foreach(以秒为单位的整数n) { _memLength=this.Getlengthofmember(n); _totalMemLength=_memLength+_totalMemLength; _memVolume=this.GetVolumeofmember(n); _totalMemVolume=\u memVolume+\u totalMemVolume; } } this.STAAD_NAME=\u stdName; this.TOTAL_MEMBER_LENGTH=_totalMemLength; this.TOTAL_MEMBER_VOLUME=_totalMemVolume; 列表=新列表(); 列表。添加(此。成员的总长度); 列表.添加(此.成员的总体积); memberData.Add(this.STAAD_NAME,list); 返回成员数据; },c#,dictionary,C#,Dictionary,在我的代码中,此foreach(第二个Dict.Values中的int n)是错误的。请告诉我如何从我的字典中的列表值中提取每个int。您的值是列表,因此您需要将n声明为列表您构建的字典有点难以处理。因此,Microsoft BCL团队引入了一种新的集合类型,称为多值字典。请查找以下链接以了解更多详细信息 因为每个值的类型都是List,并且您希望将其强制转换为int。 使用此代码: public Dictionary<string, List<double>> GetTo

在我的代码中,此
foreach(第二个Dict.Values中的int n)
是错误的。请告诉我如何从我的字典中的
列表
值中提取每个
int

您的值是
列表
,因此您需要将
n
声明为
列表

您构建的
字典
有点难以处理。因此,Microsoft BCL团队引入了一种新的集合类型,称为
多值字典
。请查找以下链接以了解更多详细信息


因为每个值的类型都是
List
,并且您希望将其强制转换为
int
。 使用此代码:

public Dictionary<string, List<double>> GetTotalLengt_VolumehofMemberUsed_AlongStaadName()
{
    var memberData = new Dictionary<string, List<double>>();
    var sec_Dict = _sectionDetails.GetAllMemberIDsWithinATable();

    string _stdName = "";
    double _memLength = 0.0; double _totalMemLength = 0.0;
    double _memVolume = 0.0; double _totalMemVolume = 0.0;

    foreach(string s in sec_Dict.Keys)
    {
        foreach(int n in sec_Dict.Values)
        {
            _memLength = this.Getlengthofmember(n);
            _totalMemLength = _memLength + _totalMemLength;
            _memVolume = this.GetVolumeofmember(n);
            _totalMemVolume = _memVolume + _totalMemVolume;
        }
    }

    this.STAAD_NAME = _stdName;
    this.TOTAL_MEMBER_LENGTH = _totalMemLength;
    this.TOTAL_MEMBER_VOLUME = _totalMemVolume;

    List<double> list = new List<double>();
    list.Add(this.TOTAL_MEMBER_LENGTH);
    list.Add(this.TOTAL_MEMBER_VOLUME);
    memberData.Add(this.STAAD_NAME, list);
    return memberData;
}

由于您的值属于
列表类型

您应该将foreach更改为:

foreach(string s in sec_Dict.Keys)
{
    foreach(int n in sec_Dict[s])
    {
        _memLength = this.Getlengthofmember(n);
        _totalMemLength = _memLength + _totalMemLength;
        _memVolume = this.GetVolumeofmember(n);
        _totalMemVolume = _memVolume + _totalMemVolume;
    }
}
foreach(在sec_Dict.Values中列出valueList)
{
foreach(值列表中的int n)
{
_memLength=this.Getlengthofmember(n);
_totalMemLength=_memLength+_totalMemLength;
_memVolume=this.GetVolumeofmember(n);
_totalMemVolume=\u memVolume+\u totalMemVolume;
}
}

Try
foreach(第二节中的int n])
很容易告诉您如何编译代码。然而,让它做一些有意义的事情需要更多的信息。我需要从列表中获取每个int。请指定,我如何获取该值?我不允许使用该值。请指定我如何使用此字典获取每个int。
 foreach (List<int> valueList in sec_Dict.Values)
 {
     foreach (int n in valueList)
     {
         _memLength = this.Getlengthofmember(n);
         _totalMemLength = _memLength + _totalMemLength;
         _memVolume = this.GetVolumeofmember(n);
         _totalMemVolume = _memVolume + _totalMemVolume;
     }
 }