Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Need to store an array of two strings

Hey

I'm making my first real tool in C# (which isn't my main language), and at some part I need to store an undefined number of usernames and passwords to get those values later, in another function.

At the moment I found this on google:

PHP Code

<?php 
List<KeyValuePair<string, string>> _items = new List<KeyValuePair<string, string>>(); 

A list of two strings, in which I add "working accounts" in a loop

PHP Code

<?php 
_items
.Add(new KeyValuePair<string, string>(username, passwords)); 

It works like a charm, but now that I want to display what's in that list (to check if I filled it earlier), I don't really know how to manipulate this "two dimensional list".

Maybe I picked the hard way, what do you think?

Basically my program works like this:

The user enters a list of usernames/password
Then I check if they're working or not one by one in a loop, and I'd like to store the working accounts in that loop
Final step is to save those working accounts in a txt file
[Image: MtOuiI0.png]
Use a dictionary or use a list of a a custom object that has a username and password property.
Lotta blood to let, peace to make, give a fuk about a check
What BahNahNah said, a dictionary would be better for this.
But if you insist on doing it this way; to get an item from the list, grab the KeyValuePair at the index you want and then interact with that.
Thanks for your anwser, I'll learn how to use Dictionnaries then
[Image: MtOuiI0.png]
Like BahNahNah said, use a dictionary!
BUT: a dictionary is composed of a key and a value. The key is your identifier in the dictionary, so be sure you don't add 2 keys with the same value.
If you have multiple entries with the same value, its not recommended to it as a disctionary key.
In this case, like BahBahBah said too, create a object like "Account" and a list which contains multiple "Accounts".
This could be a simple class with two string properties, for your example.

Sorry for bad english, hope it helps.
[Image: 39GUiXq.png]
(Oct 10, 2016 01:50 AM)hsotaka Wrote:  Like BahNahNah said, use a dictionary!
BUT: a dictionary is composed of a key and a value. The key is your identifier in the dictionary, so be sure you don't add 2 keys with the same value.
If you have multiple entries with the same value, its not recommended to it as a disctionary key.
In this case, like BahBahBah said too, create a object like "Account" and a list which contains multiple "Accounts".
This could be a simple class with two string properties, for your example.

Sorry for bad english, hope it helps.

There's no "BUT" here, what he is trying to do with a list is essentially what a Dictionary does best already. It's a list of key-value pairs, the only difference is that a Dictionary will only store one unique key per value and indexing by key will access the value associated with it.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
Edit : sry, If you do not mind the items being imutable you can use the Tuple class added to .net 4

ar list = new List<Tuple<string,string>>();
list.Add(new Tuple<string,string>("hello", "world"));

list[0].Item1 //Hello
list[0].Item2 //world

or as previously suggested use a dictionary

Dictionary<string, string> d = new Dictionary<string, string>();
d.Add("string", "string2");
(Oct 10, 2016 10:44 AM)krumpez Wrote:  u can use an arraylist also

...


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by pro_fesnoobSep 24, 2022 04:24 PM 14 797 Sep 24, 2022 04:24 PM
Last Post: BinaryFox
[C] by gurlhackerclubMay 19, 2020 05:18 PM 8 260 May 19, 2020 05:18 PM
Last Post: k1r3n
[C] by TralenSep 9, 2017 05:13 PM 7 211 Sep 9, 2017 05:13 PM
Last Post: 0xDEAD10CC