Microsoft.Net Web Site ( v2.5 ) – Error Message – “CS1002: ; expected”

Background

Have a very old .Net website that is running .Net Framework 2.5.

A couple of days added a new module to it.

Generics

The new module relies on generics.

Declare List Array

The code looks like this:-


List<int> arrTimeHour12;

arrTimeHour12 = new List<int>() 
                     {
                           0, 1, 2, 3
                         , 4, 5, 6, 7, 8
                         , 9, 10, 11, 12
                     };

 

Error Message

Here is the error message

Error Message – Text


CS1002: ; expected

Error Message – Image

 

Remediation

Code


List<int> arrTimeHour12;
									
/*	
			
  arrTimeHour12 = new List<int>()
			{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
			
*/					
			
arrTimeHour12 = new List<int>();

for (int i=0; i<=12;i++)
{
    arrTimeHour12.Add(i);
}

 

Summary

So .Net version 2.0 supports generics.

It just does not support the shorthand declaration and setting values on a single statement:-

List<int> arrTimeMinute = new List<int>(){0, 15, 30, 45};

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s