Use Lambda to find the index in the List and use this index to replace the list item.
List<string> listOfStrings = new List<string> { "abc", "123", "ghi" };
int index = listOfStrings.FindIndex(s => s == "123");
if (index != -1)
listOfStrings[index] = "def";
More Related Contents:
- What is the simplest method of inter-process communication between 2 C# processes?
- Bundler not including .min files
- How to get memory available or used in C#
- Sorting rows in a data table
- Accessing Imap in C# [closed]
- Word wrap for a label in Windows Forms
- Passing an empty array as default value of an optional parameter [duplicate]
- Anonymous method in Invoke call
- Difference with Parameters.Add and Parameters.AddWithValue
- Difference between MVC 5 Project and Web Api Project
- C# WebClient disable cache
- How to downgrade from Visual Studio 2012 project to Visual Studio 2008
- Draw on the screen without a form
- OpenSSL encryption using .NET classes
- Why does a bad password cause “Padding is invalid and cannot be removed”?
- Read appsettings json values in .NET Core Test Project
- Linq order by boolean
- Does anyone know of a good C# API for Subversion? [closed]
- using XmlArrayItem attribute without XmlArray on Serializable C# class
- ALTER TABLE DROP COLUMN failed because one or more objects access this column
- C# Closures, why is the loopvariable captured by reference?
- How to run external program via a C# program?
- How to skip the dialog of printing in printDocument.print() and print page directly?
- Accessing uploaded certificates in azure web sites
- Use chrome as browser in C#?
- How can I write a generic container class that implements a given interface in C#?
- System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated
- CefSharp 3 set proxy at Runtime
- PerformanceCounter reporting higher CPU usage than what’s observed
- How to call an explicitly implemented interface-method on the base class