控制台应用,c#输入值

编程入门 行业动态 更新时间:2024-10-14 00:30:38
本文介绍了控制台应用,c#输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有人可以告诉我如何从键盘中给出值不是静态的应用程序,这是代码的一部分,这里是值静态的:

does any one can tell me how to give the value from keyboard not to be static in application, this is the part of code here is value static:

var city = new city(5);

这是一个类

and this is a class

class city { private readonly int[] _num; private readonly int _size; public city(int Size) { _size = Size; _num= new int[_size]; }

这只是为了让你适应代码....这个数字在新的城市(5) 。我想从tast进入,但我不能......

this is just to adapt you with code.... this number that is in new city(5). I want to enter from tast,,but I cant...

推荐答案

试试这个: Hi, Try this: int cityInt = -1; try { cityInt = Convert.ToInt32(Console.ReadLine()); } catch { Console.WriteLine("Input isn't an integer!"); } if (cityInt != -1) { var city = new city(cityInt); }

希望这有帮助。

Hope this helps.

更多推荐

控制台应用,c#输入值

本文发布于:2023-11-17 08:54:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609527.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!