List Manipulation in C# using Linq

后端 未结 8 541
庸人自扰
庸人自扰 2020-12-24 12:24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace ConsoleApplication1
{

    public cla         


        
8条回答
  •  既然无缘
    2020-12-24 12:53

    Everything leppie said - plus:

    int index = mylist.FindIndex(p => p.id == 1);
    if(index<0) {
        mylist.Add(car3);
    } else {
        mylist[index] = car3;
    }
    

    This just uses the existing FindIndex to locate a car with id 1, then replace or add it. No LINQ; no SQL - just a lambda and List.

提交回复
热议问题