c# - Type and identifier are both required in a foreach statement ERROR in csharp -
i converting vb.net c# code:
dim files() string files = directory.getfiles("e:\\text", "*.txt") dim filename string dim file string each file in files filename = path.getfilename(file) i tried in c# got error
type , identifier both required in foreach statement error in csharp
string[] files; files = directory.getfiles("e:\\text", "*.txt"); string[] filenamemove; string filename; string file; foreach (file in files) filename = path.getfilename(file);
try
foreach(var file in files) you need specify type you're looping through or use var
you declared variable called file though. you'd have use different name
foreach(var f in files) { filename = path.getfilename(f); } (although logic you're overwriting filename on each iteration, unless want last filename, i'm not sure purpose of is).
Comments
Post a Comment