You can convert a string of comma-separated numbers into an array of integers using one line of code in C# by using the `Split` and `Select` methods from the LINQ library. Here's an example:

`csharp string input = "20106,20303"; int[] numbers = input.Split(',').Select(int.Parse).ToArray(); `

Explanation:

  1. The `Split(',')` method splits the input string at each comma, resulting in an array of substrings.
  2. The `Select(int.Parse)` method applies the `int.Parse` function to each substring, converting it into an integer.
  3. The `ToArray()` method converts the enumerable sequence of integers into an array.

Now, the `numbers` array will contain the integers [20106, 20303].


原文地址: https://www.cveoy.top/t/topic/pEnj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录