C#  LINQ - How to update an object

Posted on 2011-05-11
Last Modified: 2012-08-14
I have a collection of customers   -   List<Customers>

The Customer object has a  VIP property

What is the syntax to update the Customer who's name is 'SMITH' with the VIP flag = true;

How do I  select on the List, Find 'Smith' and change his flag?
Question by:JElster
    1 Comment
    LVL 74

    Accepted Solution

    You should be able to do something like this:
    List<Customers> someList = new List<Customers>() { /* assume it's initialized */ };
    var smiths = from cust in someList
                 where cust.Name.ToUpper() == "SMITH"
                 select cust;
    foreach (var smith in smiths)
        smith.VIP = true;

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    This video discusses moving either the default database or any database to a new volume.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now