vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Zippen wie die Profis!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2024
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Ein- und Umsteiger
Implicitly 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

alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Implicitly Typed Variable Declaration729Melkor24.06.07 13:45
Re: Implicitly Typed Variable Declaration450Melkor24.06.07 15:19

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

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2024 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