Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# Errors for declaring array
Message
From
08/11/2009 10:31:42
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
08/11/2009 01:16:31
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 3.0
OS:
Vista
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01433718
Message ID:
01433751
Views:
43
Probably you are not paying attention to how he does the declaration and assignment. That is not a new thing. It did error in older versions (from 1.0 and up) and it continues to error in 4.0. No code to be broken and nothing new to VS2010 or .Net 4.0. IOW there is no backward compatibility problem. He is doing the two step operation in "class member definition". Try this in any version you want:
class test
{
  string[] myStrings;
  myStrings = new string[10];

  static void Main() { // Try compiling this in any version you wish
  }
}
Correct one would be:
class test
{
  string[] myStrings = new string[10];

  static void Main() { // Try compiling this in any version you wish
  }
}
Cetin

>Well, that's sure to break a lot of developers code. Whatever happened to backward compatibility? Are these actual errors (won't compile at all) or simply warnings? (I don't have VS 2010 installed yet, so I can't see for myself).
>
>But, I did go and read the link you provided, and that's not what I get out of reading it. It says you *can* do what you were doing:
>
>It is possible to declare an array variable without initialization, but you must use the new operator when you assign an array to this variable. For example:
>
>int[] array3;
>array3 = new int[] { 1, 3, 5, 7, 9 }; // OK
>//array3 = {1, 3, 5, 7, 9}; // Error
>

>
>Is the documentation wrong or is there a bug? Anyone else get around to trying this in VS 2010 yet?
>
>
>~~Bonnie
>
>
>
>
>>Okay, I did some digging in the MSDN help for Visual Studio 2010 Beta 2. It seems that Microsoft has changed the creation and initializing of arrays from a 2-step Texas jig to a 1-step Tennessee crawl, as follows:
>>
>>http://msdn.microsoft.com/en-us/library/0a7fscd0(VS.100).aspx
>>
>>Here's an example of how you'd set up an array of 10 integer array elements, and the same for a string array of 10 elements. It's a 1-step process in Visual Studio 2010 for C#. I tried it and there were no longer any errors.
>>
>>
>>int[] numbers = new int[10];
>>string[] strMyStringArray = new string[10];
>>
>>
>>Cecil
>>
>>>I'll try this later in VS 2010, but first - what are the errors? I found I learned most of my syntax stuff by just hovering over any code that was wavy lined and letting the IDE tell me what the problem was.
>>
>>>>Why would the below simple declaration/initialization give me three errors in VS 2010 (C#)? I tried this in Visual Studio 2008 and it worked perfectly? Could this be a bug in Visual Studio 2010 Beta 2?
>>>>
>>>> string[] strMyArray;
>>>> strMyArray = new string[10];
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform