C尖锐的小疑问 [英] small doubt in c sharp
本文介绍了C尖锐的小疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,正在获取输出,但哈希表,字典和表的末尾没有空格.在这里我需要3个函数之间的空格..
This is my code , am getting the output but there is no space after the end of hash table , dictionary and table. here i need spaces between 3 functions..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Array_List
{
class Program
{
static void Main(string[] args)
{
Program pg = new Program();
pg.HashTable();
pg.Dictionary();
pg.table();
Console.ReadLine();
}
public void HashTable()
{
Hashtable h = new Hashtable();
h.Add(1, "Sunday");
h.Add(2, "Monday");
h.Add(3, "tuesday");
h.Add(4, "Wednesday");
h.Add(5, "Thursday");
h.Add(6, "Friday");
h.Add(7, "Saturday");
//h.Add(8, " ");
for (int j = 1; j <= h.Count; j++)
{
Console.WriteLine(h[j]);
}
// Console.ReadLine();
}
public void Dictionary()
{
Dictionary<int,> dict = new Dictionary<int,>();
dict.Add(1, "Jan");
dict.Add(2, "Feb");
dict.Add(3, "Mar");
dict.Add(4, "Apr");
dict.Add(5, "May");
dict.Add(6, "June");
dict.Add(7, "July");
dict.Add(8, "Aug");
dict.Add(9, "Sept");
dict.Add(10, "Oct");
dict.Add(11, "Nov");
dict.Add(12, "Dec");
for (int k = 1; k <= dict.Count; k++)
{
Console.WriteLine(dict[k]);
}
// Console.ReadLine();
}
public void table()
{
ArrayList names = new ArrayList();
names.Add("ARUL");
names.Add("POO");
names.Add("KAYAL");
names.Add("MOM");
names.Add("DAD");
for (int i = 0; i <= names.Count; i++)
{
Console.WriteLine(names[i]);
}
}
}
}
推荐答案
Console.Writeline有一个重载的方法.当您不带任何参数使用它时,它将跳过当前行,并且光标将移至下一行.
检查此更正的代码
Console.Writeline has a overloaded method. When you use it without any parameters, it skips the current line and the cursor moves to next line.
Check this corrected code
static void Main(string[] args)
{
Program pg = new Program();
pg.HashTable();
Console.WriteLine();
pg.Dictionary();
Console.WriteLine();
pg.table();
Console.WriteLine();
Console.ReadLine();
}
您有什么疑问?它正在按应有的方式工作. WriteLine在文本之后不添加任何空格,而是添加一个carriage-return + newline
:下一个文本将在下一行的第一位置开始.在需要空行的地方添加额外的Console.WriteLine();
.
And what is your doubt? It is working as it should work. WriteLine adds no space after the text, it adds acarriage-return + newline
: the next text written will start at the first position of the next row. Add an extraConsole.WriteLine();
where you need an empty row.
这篇关于C尖锐的小疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文