本文介绍了如何转换并将字符串/字符串值分配给Windows窗体中的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想将字符串值转换为List.How转换为。 这是我的代码。Hi, I want to convert string value to List.How to Convert this. Here is My Code.private void TestGridData_CellContentClick(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = new DataGridViewRow(); List<string> TestName = new List<string>(); int I = TestGridData.CurrentCell.ColumnIndex; string Head = TestGridData.Columns[I].Name; if (Head == "check") { row = TestGridData.CurrentRow; int row2 = row.Index; TestCost = Convert.ToInt32(TestGridData[2, row2].Value); string Name = TestGridData[1, row2].Value.ToString(); } // TestName=Name as List<string>; sum = sum + TestCost; txtcost.Text = sum.ToString(); } 存储在名称和列表中的字符串值存储在TestName中。如何将此名称转换为List.In这是我试过的注释行,但是没有得到正确的输出。 请帮我输出正确的输出 And the string value stored in Name and list stored in TestName.How to convert this Name to List.In this the commented line i tried but i didn't get correct output. Please help me to get correct output推荐答案if (Head == "check") { row = TestGridData.CurrentRow; int row2 = row.Index; TestCost = Convert.ToInt32(TestGridData[2, row2].Value); string Name = TestGridData[1, row2].Value.ToString(); TestName.Add(Name) }TestName.Add(Name) 和一件事,你必须将范围列为范围,以便它可以包含不同的项目。 有关List(t).Add方法的更多信息,请按照 列出< t> .Add方法and one thing , you have to declare the List out side the scope ,so that it can contain different item .For more information about List(t).Add method followList<t>.Add Method 这篇关于如何转换并将字符串/字符串值分配给Windows窗体中的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!