Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..

C#
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]);
            }
        }
    }
}
Posted
Updated 14-Sep-12 21:30pm
v2
Comments
CoderVivs 15-Sep-12 3:45am    
just keep Console.WriteLine() afte the for loops.
And in the function table() improve the for loop condition with
i < names.count;

And what is your doubt? It is working as it should work. WriteLine adds no space after the text, it adds a carriage-return + newline: the next text written will start at the first position of the next row. Add an extra Console.WriteLine(); where you need an empty row.
 
Share this answer
 
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

C#
static void Main(string[] args)
{
          Program pg = new Program();

         pg.HashTable();
         Console.WriteLine();
         pg.Dictionary();
         Console.WriteLine();
         pg.table();
         Console.WriteLine();
         Console.ReadLine();
 
} 
 
Share this answer
 
v3
Comments
AmitGajjar 15-Sep-12 4:01am    
correct 5+
bbirajdar 15-Sep-12 4:04am    
Thank you Amit :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900