So i'm trying to do something like a Point counter..
The code that i will show you below prints something like:
Code:Code:Person3 Person2 Person1 69 70 71
What i cant do and I've been searching for hours is.. to connect these two arrays into a one string.Code:int[] values = sth.Values.ToArray(); string[] keys = sth.Keys.ToArray(); Array.Sort(values, keys); foreach(string key in keys) Puts(key.ToString()); foreach(int num in values) Puts(num.ToString());
Thanks for any help,
PaiN
Sorted Arrays into one string
Discussion in 'Rust Development' started by PaiN, Nov 6, 2015.
-
What type of output string are you trying to form?
Something like:
Person3: 69,
Person2: 70,
Person1: 72 -
Yes exactly this
-
Code:
Dictionary<string, int> sth = new Dictionary<string, int>() { { "Person 1", 69}, { "Person 2", 70}, { "Person 3", 72} };foreach(KeyValuePair<string, int> entry in sth) { Puts($"{entry.Key}:{entry.Value}"); } -
Yeah .. and what i want is to make a list with top3 "points" dunno how to call it. With Array.Sort I've managed to sort random values ex. {30, 40, 25, 100} from the higher number to lower and the Key of it with the code that i will show you below.
100
40
30
25
Once i type Test It shows: Check this screenshot! (Click it)Code:class Test : RustPlugin { public Dictionary<string, int> sth = new Dictionary<string, int>(); void Loaded() { sth.Add("Person2", 55); sth.Add("Person3", 50); sth.Add("Person1", 71); } [ConsoleCommand("test.test")] void cmdTestT(ConsoleSystem.Arg arg) { int[] values = sth.Values.ToArray(); string[] keys = sth.Keys.ToArray(); //Array array = players; Array.Sort(keys, values); foreach(string key in keys) Puts(key.ToString()); foreach(int num in values) Puts(num.ToString()); } }
How would i do these 2 seperated (Key & Value) into a one string ? -
Code:
Dictionary<string, int> sth = new Dictionary<string, int>() { { "Person 1", 69}, { "Person 2", 70}, { "Person 3", 72} }; var sortedDict = from entry in sth orderby entry.Value descending select entry; foreach(KeyValuePair<string, int> entry in sortedDict) { Puts($"{entry.Key}:{entry.Value}"); } Puts(string.Join(",", sortedDict.Select(x => x.Key + ":" + x.Value))); Person 3:72 Person 2:70 Person 1:69 Person 3:72,Person 2:70,Person 1:69 -
Thank you
