Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# Errors for declaring array
Message
De
08/11/2009 11:38:53
 
 
À
08/11/2009 10:31:42
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 3.0
OS:
Vista
Database:
Visual FoxPro
Divers
Thread ID:
01433718
Message ID:
01433759
Vues:
40
>Probably you are not paying attention to how he does the declaration and assignment.

Yes, I see what you mean and that is what I must have missed. I forgot that Cecil is a n00b and would probably easily have made that mistake. My bad for missing that.

Thanks Cetin.

~~Bonnie


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];
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform