简体   繁体   中英

How to fix this foor loop error in vb.net (windows phone)

I have an error regarding this for loop. Var is not declared so it gives an error, however Var is not a declaration.

For Each file As var In files
Debug.WriteLine("Deleting... " & Convert.ToString(file))
isf.DeleteFile(file)
Next

Simple, Var isnt a type. remove the as var , it is useless.

Let the compiler use inferation, or specify the correct type (file I imagine)

For Each file In files 
    Debug.WriteLine("Deleting... " & Convert.ToString(file))
    isf.DeleteFile(file)
Next

or

For Each file as File In files 
    Debug.WriteLine("Deleting... " & Convert.ToString(file))
    isf.DeleteFile(file)
Next

Edit : explanation concerning the for each : If you dont specify a type for your iterator (the file in your case), the compiler is going to try and determine the type of it for you.

In some hairy cases, it wont be able to determine the correct type, so you will have to specify it for him, by using the as . But in your case, I believe the for each will work without specifying the type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM