c# - 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**
解决方案
我真的不知道您要做什么,但是如果您要尝试将 char 转换为 ASCII 值,那么您将不得不使用Char
调用的静态方法GetNumericValue
。
GetNumericValue
可在此处找到有关信息: https ://docs.microsoft.com/en-us/dotnet/api/system.char.getnumericvalue?view=netcore-3.1
推荐阅读
- powershell - 管道元素 Powershell 中的“,”后缺少表达式
- python - Pip 安装了我想使用的模块,但仍然出现“找不到模块”错误
- javascript - 缓存 observables 导致 mergeMap 出现问题
- json - 如何使用 az 命令为 jmespath 查询添加和条件
- java - 执行 Maven 构建时缺少所需的类
- python - 仅保留 MT940 文件中的最新标签
- javascript - 节点将相对路径转换为绝对路径,不需要
- node.js - 如何填充填充对象属性的值
- python - Dash Plotly 中带有下拉菜单的“全选”
- asp.net - 如何在aspx文件中使用if语句