c#中的数字编码 [英] Number coding in c#..

查看:122
本文介绍了c#中的数字编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#中添加数字行。如果我必须输入许多名称,我需要编写Console.WriteLine(Name);

name = Console.ReadLine();在每一行或有另一种方式。

是存储的名称还是我必须存储它以便我可以使用它?

How do I put number lines in c#. And if I have to enter many names do i need to write Console.WriteLine("Name");
name = Console.ReadLine(); in every line or is there another way.
And are the name stored or do I have to store it so I can use it ?

推荐答案

你可以在VS中显示行号很容易: http://msdn.microsoft.com/en-us/library/ms165340.aspx [ ^ ] - 但很少打扰更多,因为当前行和列号显示在状态栏上,双击错误消息将带您直接到达该行。



如果你想要读取多个名称并将它们全部存储起来,那么有两种方法可以做到:

1)如果你事先知道你想要多少名字,请使用数组:

You can show line numbers in VS very easily: http://msdn.microsoft.com/en-us/library/ms165340.aspx[^]- but few bother any more, because the current line and column number is shown on the status bar, and double clicking an error message will take you right to the line anyway.

If you want to read a number of names and store them all, then there are two ways you can do it:
1) If you know in advance how many names you want, use an array:
int numberOfNames = 10;
string[] names = new string[numberOfNames];
for (int i = 0; i < numberOfNames; i++)
   {
   names[i] = Console.ReadLine();
   }



2)如果你不知道invance,请使用一个清单:


2) If you don't know in andvance, use a List:

List<string> names = new List<string>();
while (true)
   {
   string name = Console.ReadLine();
   if (string.IsNullOrWhitespace(name)) break;
   names.Add(name);
   }


这篇关于c#中的数字编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆