string formIdList = "8256,8258,8362,8120,8270,8271,8272,8273,8257,8279,8212,8213,8214,8215,8216,8217,8218,8219,8231,8232,8233,8234,8235,8242,8248,8251,8252,8254,8255,8262,8263,8264,8265,8266,8290,8292,8293,8294,8300,8320,8230,8227,8226,8225,8224,8223,8222,8221,8291,8261,8241,8228,8220,8211,8208,8207,8206,8205,8204,8203,8202,8201,8153,8151,8150,8130,8122,8000,8101,8102,8103"; var temp = formIdList.Split(','); List<int> ids = new List<int>();
我需要将temp加载到id中.我可以使用for循环,但我确信有更好的方法.
解决方法
您可以使用LINQ:
string formIdList = ... List<int> ids = formIdList.Split(',').Select(int.Parse).ToList();