🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #3361

Re: enkele VB .NET vraagjes

#3361
From: Lazarus Lang
Date: Sat, 03 Jan 2004 11:33
41 lines
2834 bytes
Snuyt, mijn antwoorden inline...

"Snuyt" <snuyt_nospam@skynet.be> wrote in message news:3ff57589$0$6628$ba620e4c@news.skynet.be...
> dim col as collection    'collection van objecten van klasse A

Niet noodzakelijk van klasse A, zoals je zelf al schreef. :)


> public function iets(b as A) as A
>      dim a1, a2 as A
>      for each a1 in col
>          if (b.value() = a1.value()) then a2=a1
>      next
>      return a2
> end function


> 1. aangezien het niet gedefinieerd is welke objecten er in een
> collection zitten, weet de compiler dat er in de for each lus met
> objecten van klasse A gewerkt wordt? Wordt dit op een impliciete manier
> gecast of zo?

Ja, dat gebeurt in de achterliggende IL code van de "for each". Daar gebeurt
een enumeratie en een conversie naar het type A. Als dat niet lukt krijg je
wsch. een InvalidCastException in je gezicht gesmeten. Trouwens, als je
even de moeite neemt om te sjekken op je MSDN cd (of op de site) lees
je bij For Each het volgende:

"A For Each...Next statement loops based on the elements in an expression. A For Each statement specifies a loop control variable
and an enumerator expression. The type of the value returned by the expression in the For Each statement must be a collection type
(defined below), and an implicit conversion must exist from the element type of the collection to the type of the loop control
variable. ... "

> 2. het is ook mogelijk dat er in col geen enkel object zit, gelijk aan
> b. Wat wordt er dan door de functie weergegeven? 'Nothing'? Runtime Error?

Nothing. Alle variabelen in VB.Net worden (net zoals in de klassieke VB vroeger)
geinitialiseerd op 0 (voor numerieke variabelen) of Nothing (voor object references
v/h type String (!), Integer (!!!), Form, etc...)

eltwo
Technical Details
Message-ID: <7MxJb.112388$Kw4.5123179@phobos.telenet-ops.be>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!easynet-quince!easynet.net!feed1.news.be.easynet.net!ossa.telenet-ops.be!phobos.telenet-ops.be.POSTED!not-for-mail
References: <3ff57589$0$6628$ba620e4c@news.skynet.be>

Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit
X-Google-Thread: fcea4,8186e858ea887395
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2004-01-03 03:33:24 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!easynet-quince!easynet.net!feed1.news.be.easynet.net!ossa.telenet-ops.be!phobos.telenet-ops.be.POSTED!not-for-mail
From: "Lazarus Lang" <lazaruslang@yahoo.com>
Newsgroups: be.comp.programming
References: <3ff57589$0$6628$ba620e4c@news.skynet.be>
Subject: Re: enkele VB .NET vraagjes
Lines: 43
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <7MxJb.112388$Kw4.5123179@phobos.telenet-ops.be>
Date: Sat, 03 Jan 2004 11:33:23 GMT
NNTP-Posting-Host: 81.82.10.219
X-Complaints-To: abuse@telenet.be
X-Trace: phobos.telenet-ops.be 1073129603 81.82.10.219 (Sat, 03 Jan 2004 12:33:23 MET)
NNTP-Posting-Date: Sat, 03 Jan 2004 12:33:23 MET
Organization: Telenet Internet