首页 > 解决方案 > c#用户输入整数数组以查找特定数字

问题描述

我是编程新手,我使用 c# 来解决一些问题,但是当用户在同一行中输入两个整数 no 时我遇到了问题,我想查找零并将其从我认为的每个 no 中删除,方法是替换为我应该转换的下一个数组单元格整数再次字符串,但我做不到请帮助我

 string[] arr = Console.ReadLine().Split(' ');
        string a = arr[0];
        string b = arr[1];
        int[] m = new int[1];
        int[] n = new int[1];



        for (int i = 0; i < a.Length; i++)
        {

            if (a[i] == 0 && a[a.Length - 1] != 0)
            {
                for (int j = i; j < a.Length; j++)
                {
                    //****m[i] = int.Parse(a[i]); the error here cant convert from char to string ??
                 //   a[i] = a[i + 1];**\\ Error    CS0200  Property or indexer 'string.this[int]' cannot be assigned to -- it is read only**   

标签: c#arraysuser-input

解决方案


我真的不知道您要做什么,但是如果您要尝试将 char 转换为 ASCII 值,那么您将不得不使用Char调用的静态方法GetNumericValue

GetNumericValue可在此处找到有关信息: https ://docs.microsoft.com/en-us/dotnet/api/system.char.getnumericvalue?view=netcore-3.1


推荐阅读