5

Find and remove a tuple from the list of tuples in C # 4.0

 2 years ago
source link: https://www.codesd.com/item/find-and-remove-a-tuple-from-the-list-of-tuples-in-c-4-0.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Find and remove a tuple from the list of tuples in C # 4.0

advertisements

I have created a list of tuples:

static List<Tuple<string, string>> Alt;

The user adds to this list:

Alt.Add(new Tuple<string, string>(tbAlt.Text, ""));

What is the best way to find a Tuple based on the first string (i.e. the tbAlt.Text ) and either delete it or modify the second string?

I am new to using Tuples and lists :)

Many thanks for any help!


It appears the first string must be unique or you would not find a (singular)

Why are you using List<Tuple<string, string>>?

Why not Dictionary<string,string>?

Dictionary<TKey, TValue>.ContainsKey is very very fast.

Dictionary.ContainsKey

Related Articles

Find and remove an item from the list

Is there a way to remove an item from a listbox based on a string? I have been playing around for a few minutes and here is what i have so far but its not working foreach(string file in LB_upload.Items) { ftp.Upload(file); int x = LB_upload.Items.Ind

C # - Find and remove a substring from a list of strings

I have a bad word list. If a string contains any of item/items from the bad word list, I need to remove that bad word from the string. List<string> badWordList = new List<string> { "email:", "index", "mobile:", &q

How do I remove duplicate items from the list of numpy arrays?

I have a list of numpy arrays. How can I can remove duplicate arrays from the list? I tried set(arrays) but got the error "TypeError: unhashable type: 'numpy.ndarray" Example with 2d arrays (mine are actually 3d). Here the starting list is lengt

Randomly selects the value of the array and removes that value from the array

Trivial question. What I have so far http://jsfiddle.net/Dth2y/1/ Task, the next button should randomly select a value from the array and remove that value from the array. So far this called the getNames function, within this function the value rando

Remove duplicate duplicates from the list of tuples

So basically I have a list of tuples [(a,b)], from which i have to do some filtering. One job is to remove inverted duplicates such that if (a,b) and (b,a) exist in the list, I only take one instance of them. But the list comprehension has not been v

Find a case-sensitive string in a cell from a specific list and return a value from the list

I am stumped. I need Excel to search in a cell (Sheet 1, column a) and find a specific string of text from a list (Sheet 2, column a). Then if it finds that specific string of text from the list (Sheet 2, column a), I need it to return the value from

A method that adds and removes an item from a list

i'm writing a method that take a list: List[(String, Int)] , x:(String, Int) and a n: Int parameters and return a List[(String, Int)] The list parameter represents the input list, the x element represents the element to add to the list, the n represe

Python removes specific brands from the list

I have this kind of list: ['8 ', '27', '90+1 ','27','90+3','47'] My goal is to get it like this: ['8', '27','90','27','90','47'] How I can remove the "+" marks and next numbers from the list?You can use the following expression: [x.split('+',1)[

What to return when removing a dto from the list

I have a service oriented architecture. The client holds a list of parent and child dtos that are bound to the front end. The service for this is a get that returns the full list of everything. When deleting is it better to: a. remove the object from

Windows Metro App Filtering Listview and showing specific data from the list?

I am not aware if there is any "callback" to Listview creation so that i can display very specific type of data from the List i have. What i know is that only Complete List can be bound to the ListView, but how can i put some checking to it like

Python accepting user input and removing this entry from a list

I have been trying this for a few days now. I have to read in a file containing zoo animals. (i.e. ['ID', 'Name', 'Species']) Next, have to accept the user's ID choice and delete from the list. This is what I so far. I am stuck and can't proceed furt

Find a pattern in string and remove this pattern from the Excel cell chain without touching the pattern in the middle of the string

I have a column which has "--" pattern in the beginning, middle and end of the string. For example: -- myString my -- String myString -- I want to find these two types of cells -- myString myString -- and remove the "--" pattern, so it

python 3.x add a list and remove an item from the old list

I was wondering if there was a way of shorting this code by using a list comprehension. I have tried to use them by every time the loop runs the last ltems in the loop are all I get. This is what I tried. list2 = [i for i in list1 if i[0] == counter]

Thread-safe finds and removes an object from a collection

I wonder how can I do something like the following class MyCollection<E> implements Collection<E> { @Nullable E findAndRemove(Predicate<E> predicate) { for (E e : this) { if (predicate.test(e)) { remove(e); return e; } } return null; } }

Removing all duplicates from the list - without any instance of a duplicate item

I've got a list: myList = [-3, -3, 6, 10, 10, 16, 16, 40, 40, 60, 60, 100, 100, 140, 140, 211, -8] how can I efficiently remove all the duplicated items from the, i.e. to have a new list like this: [6,211,-8] I know a way to do it, by keeping a track

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK