delete in c# code example

Example 1: how to delete from a list c#

var resultList = new List<int>();
resultList.Add(1);
resultList.Add(2);
resultList.Add(3);

// Removes the number 1 from the index 0 in the list
resultlist.RemoveAt(0);

// Allows you to remove an Object from the list instead
var itemToRemove = resultlist.Single(r => r.Id == 2);
resultList.Remove(itemToRemove);

Example 2: c# remove

//using System;
string myString = "Hello Grepper Developers";

//Removing all characters starting from a position
string newStr = myString.Remove(5);
	//Output: Hello

//Removes a specified number of characters after starting from a position
string newStr2 = myString.Remove(5, 8);
	//Output: Hello Developers