Ar “dinamisku” braukšanu esiet uzmanīgi!

Atkārtošanai pieminēšu, ka līdz ar jaunās platformas (.NET 4.0) izstrādātājiem būs pieejama interesanta iespēja statiski deklarēt mainīgo par dinamisku un tā vērtību noteikt tikai izpildes režīmā.

Izklausās diezgan aizraujoši un interesanti, bet kopsummā ar jauno dynamic atslēgas vārdu jābūt brīžiem arī uzmanīgiem.

Piemēram, šāds koda fragments ved uz domām, ka šāda veida konstrukcijas taču acīmredzami nav pieļaujamas:

static int Foo(string s) { return 0; }
static void Main()
{
    dynamic x = "this is a stirng";
    DateTime d = Foo(x);
}

 

Beigās iegūstam sekojošu kļūdas situāciju:

 

Picture 1

 

No vienas puses šāda veida konstrukcija ir acīmredzami nepieļaujama, bet dymanic atslēgvārds reglamentē to, ka kompilācijas laikā visas tipu pārbaudes ir atslēgtas. Tā kā, ar dymanic ir jābūt uzmanīgiem. Kompilācijas izstrādes komanda plāno izveidot vismaz brīdinājuma ziņojumus par šādām situācijām līdz RTM versijai.

 

 

Cerams, ka noderēs!

Published Monday, July 20, 2009 6:51 PM by valdis.iljuconoks

Comments

# hei!

Beneficial, they on donation to be taught that filing lawsuits is not the silhouette of performance to prolonged recounting eccentric piracy. Repute than, it's to skiff something mastery than piracy. Like placidity of use. It's perfectly a gargantuan numbers easier to utter iTunes than to search the Internet with jeopardy of malware and then crappy idiosyncrasy, but if people are expected to surrejoinder on the sake of loads and be included at to seeing that ages, it's not prolific to work. They barely origination a feign every so convenience life again old-fashioned on people sire software and Spider's web sites that interchange it ridiculously weak to infringer, and up the quality. If that happens, then there specify be no stopping piracy. But they're too circumspect and appalled of losing. Risks anchored to be in seventh heaven!

<a href='lordsofthenewchurch.com/index.php church</a>

Friday, January 14, 2011 8:17 PM by Velawhathetle

# Interesting, thanks

This website is certainly relatively helpful given that I’m on the instant making an online floral internet site - despite the fact that I'm only commencing out for that reason it is genuinely pretty tiny, absolutely nothing such as this web site. Can website link to some in the posts right here because they are very. Many thanks significantly. Zoey Olsen

Wednesday, November 16, 2011 11:13 PM by Jake Knie

# IyzHGsRxXpV

dupYT4 Very informative post.Really looking forward to read more. Great.

Friday, March 23, 2012 2:15 PM by buy google +1

Leave a Comment

(obligāts) 
(obligāts) 
(brīvizvēles)
(obligāts)