when i execute the below progam i am getting this errror type or namespace definition, or end-of-file expected in c#

using System;


class Program
{
          public static void Main(string [ ] args){

	string[] colorList =new string[10];

                    colorList[0] = "sunday";
                    colorList[1] = "monday";
                    colorList[2] = "tuesday";
                    colorList[3] = "wednesday";
                    colorList[4] = "thursday";
                    colorList[5] = "friday";
                   colorList[6] = "saturday";
                       

             		 for( int  i =0;  i < 10;  i++)
		{

		Console.WriteLine("Color is: {0}", colorList[i]);
	   	}
                
	                      Console.ReadLine();
	           
                    }

}

>type or namespace definition, or end-of-file expected in c#

Error causes when a source code file does not have a matching set of braces.

using System;


class Program
{
    public static void Main(string[] args)
    {
        string[] colorList = new string[10];

        colorList[0] = "sunday";
        colorList[1] = "monday";
        colorList[2] = "tuesday";
        colorList[3] = "wednesday";
        colorList[4] = "thursday";
        colorList[5] = "friday";
        colorList[6] = "saturday";

        for (int i = 0; i < 10; i++)
        {

            Console.WriteLine("Color is: {0}", colorList[i]);
        }
        Console.ReadLine();
    }
}

Hi mate...code seems to be fine...just put a curly brace to close the namespace and you should be good to go....

although because you have declared 10 items in your array....

your going to get it list the days "colour is -whatever-" then your going to have another 3 lines that just say "colour is -blank-", that is not supposed to sound condescending in any way....

This article has been dead for over six months. Start a new discussion instead.