| |

VB.NET - Ein- und UmsteigerImplicitly Typed Variable Declaration | |  | Autor: Melkor | Datum: 24.06.07 13:45 |
| VS Orcas Prof gerade installiert, versuche ich es für den Anfang mit dem bekannten Beispiel aus MSDN und stolpere schon bei der ersten Deklaration. Bei
Dim countries = { _
New Country With { .Name = "Palau", .Area = 458, .Population = 16952 }, _
New Country With { .Name = "Monaco", .Area = 1.9, .Population = 31719 }, _
New Country With { .Name = "Belize", .Area = 22960, .Population = 219296 }, _
New Country With { .Name = "Madagascar", .Area = 587040, .Population _
=13670507}} bekomme ich die Meldung
Array initializers are valid only for arrays, but the type of 'countries' is 'Object'
Häh? Und bei dem weiteren Code
Dim smallCountries = From country In countries _
Where country.Population < 1000000 Select country
For Each country In smallCountries
Console.WriteLine(country.Name)
Next dann
Expression of type 'Object' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.
Was man dann auch verstehen kann. Aber laut MSDN
The declaration also illustrates implicitly typed local-variable declarations, where the compiler infers the type of the local variable Countries from the initializer expression on the right side of the declaration. The declaration above is precisely equivalent to an explicitly typed local-variable declaration of type Country().
Copy Code
Dim countries As Country() = {...}
To repeat, this is still a strongly typed declaration; the compiler has automatically inferred the type of the right side of the local declaration, and there is no need for the programmer to enter that type into the program manually.
Vorsichtshalber habe ich Option Infer On und Imports System.Linq geschrieben, hat aber nichts gebracht. Nun, was ist? Da es schon Leute hier gibt mit anscheinend langfristiger VB 9 Erfahrung hoffe ich auf eine rasche Antwort.
Those people who think they know everything are a great annoyance to those of us who do - Isaac Asimov |  |
 | Sie sind nicht angemeldet! Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.
Einloggen | Neu registrieren |
  |
|
Neu! sevEingabe 3.0 
Einfach stark!
Ein einziges Eingabe-Control für alle benötigten Eingabetypen und -formate, inkl. Kalender-, Taschenrechner und Floskelfunktion, mehrspaltige ComboBox mit DB-Anbindung, ImageComboBox u.v.m. Weitere InfosTipp des Monats Oktober 2025 Matthias KozlowskiUmlaute konvertierenErsetzt die Umlaute in einer Zeichenkette durch die entsprechenden Doppelbuchstaben (aus ä wird ae, usw.) TOP Entwickler-Paket 
TOP-Preis!!
Mit der Developer CD erhalten Sie insgesamt 24 Entwickler- komponenten und Windows-DLLs. Die Einzelkomponenten haben einen Gesamtwert von 1866.50 EUR...
Jetzt nur 979,00 EURWeitere Infos
|
|
|
Copyright ©2000-2025 vb@rchiv Dieter Otter Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.
Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel
|
|