Public class cartitem {
Public int proid {Get; set ;}
Public String proname {Get; set ;}
Public int num {Get; set ;}
}
List <cartitem> List = new list <cartitem> ();
// Add function
For (VAR I = 0; I <10; I ++)
List. Add (New cartitem ()
{
Proid = I,
Proname = "Product xx" + I,
Num = 3
});
// Add end
Response. Write ("============= after modification ============== ");
Response. Write ("<br/> ");
// Change the number of shopping items with the product ID 3 to 880
List. foreach (t => {If (T. proid = 3) T. num = 800 ;});
List. foreach (x =>
{
Response. Write (X. proid + "" + X. proname + "" + X. Num );
Response. Write ("<br/> ");
});
List. foreach (t => {If (T. proid = 4) List. Remove (t );});
Response. Write ("============= after deletion ============== ");
Response. Write ("<br/> ");
List. foreach (x =>
{
Response. Write (X. proid + "" + X. proname + "" + X. Num );
Response. Write ("<br/> ");
});
Response. Write ("============== If yes, the number of updates after ================== ");
Response. Write ("<br/> ");
VaR newlist = List. Where (t => T. proid = 99). tolist ();
If (newlist. Count> 0) List. foreach (t => {If (T. proid = 99) T. num = T. Num + 1 ;});
Else list. Add (New cartitem (){
Proid = 99,
Proname = "new name ",
Num = 1
});
List. foreach (x =>
{
Response. Write (X. proid + "" + X. proname + "" + X. Num );
Response. Write ("<br/> ");
});