Tuesday 15 April 2014

c# - Boolean statement where extra parenthesis are required -



c# - Boolean statement where extra parenthesis are required -

public class part { public string vendorid { get; set; } public string vendorpart { get; set; } public string basepart { get; set; } public string description { get; set; } public imageviewtype view { get; set; } } private list<part> partlist = null; private bool deleteoldfile = false;

i'm curious why next code works (once partlist loaded data):

foreach (part p in partlist) { deleteoldfile = ((partlist.last().basepart) == (p.basepart)); movefile(filetype.image, p, getsetimagefile(imagebox1, currentfile)); }

and next not work (never sets boolean deleteoldfile true):

foreach (part p in partlist) { deleteoldfile = (partlist.last().basepart == p.basepart); movefile(filetype.image, p, getsetimagefile(imagebox1, currentfile)); }

there's no difference between these 2 options. cause of problem because override value of deleteoldfile every iteration. think wanted write this:

foreach (part p in partlist) { deleteoldfile = deleteoldfile || partlist.last().basepart == p.basepart; movefile(filetype.image, p, getsetimagefile(imagebox1, currentfile)); }

c# boolean

No comments:

Post a Comment