C# specflow 테이블에서 사전을 만들고 싶습니다. 레이블의 값으로이 값이 필요하며 모든 기능 파일에 대한 값이 변경됩니다. 현재 기능 파일에는 2 개의 열이 있습니다.specflow 테이블을 todictionary로 변환
And I submit with following
| Label | Value |
| Namelabel | texttoenter123 |
| Email |[email protected] |
해당 단계. linq를 사용했습니다.
[When(@"I submit with following ")]
public void WhenISubmitWithFollowing(Table table)
{
//Should be something like this , which convert the table todictionary object
var x = table.Rows.ToDictionary(k=>k.Keys,k=>k.Values);
}``
현재이 문제는 null입니다. 도움을 받으십시오. 당신은 다음과 같은 주요
DataTable dt = new DataTable();
dt.Columns.Add("Label", typeof(string));
dt.Columns.Add("Value", typeof(string));
dt.Rows.Add(new object[] { "Namelabel", "texttoenter123" });
dt.Rows.Add(new object[] { "Email", "[email protected]" });
Dictionary<string, string> dict = dt.AsEnumerable()
.GroupBy(x => x.Field<string>("Label"), y => y.Field<string>("Value"))
.ToDictionary(x => x.Key, y => y.FirstOrDefault());
사용 당 하나 개의 값을 가질 경우
이것은 내가 찾던 것이다. 그것은 효과가 있었다. 감사 – Shanti