c# - Use of Unassigned Local variable when adding item in listview -


I am trying to compare if the item is already present in the list view.
It says:

Assign local variable 'already use' list

  bool already installed ; Foreach (var itm in lvCart.Items) {if (itm == item) {already InList = true; break; }} If (already inelist!) {LvCart.Items.Add (New ListViewItem (new string [] {item, price, noi})); } 

Others have said how you can avoid certain assignment problems.

However, I suggest using LINQ to simplify the code by any means:

  bool already InList = lvCart. Items.Contains ( item); Depending on the type of  

( item , you may need something like lvCart.Items.Cast & lt; SomeType & gt; () It contains (item) .)


Comments