I'm currently having this code:
List<int> list = new List<int>();
list.Add(0);
list.Add(1);
list.Add(2);
list.Add(3);
color0 = list[1];
color1 = list[2];
color2 = list[3];
color3 = list[4];
Is there a possible way, this list could take 2 arguments in 1 element? What I mean is:
List<int,int> list = new List<int,int>();
list.Add(0,3);
list.Add(1,8);
color0=list[1][2]; //output 3
color1=list[1][1]; //output 0
color2=list[2][2]; //output 8
color3=list[2][1]; //output 1
Is there a possible was i can achieve something similar to this?
You can add as many parameters as you want, just separate them with a comma.
Passing two lists and 'sum' function to map() Passing sum function, list1 and list2 to map(). The element at index 0 from both the list will pass on as argument to sum function and their sum will be returned. This loop continues till elements of one list get exhausted. The result will be stored in result list.
You can send any data types of argument to a function (string, number, list, dictionary etc.), and it will be treated as the same data type inside the function.
In Python, functions can take either no arguments, a single argument, or more than one argument.
You can use Tuple
:
var list = new List<Tuple<int, int>>();
list.Add(new Tuple<int, int>(1, 2));
For easier use you can create an extension method:
public static class Extensions
{
public static void Add(this List<Tuple<int, int>> list, int x, int y)
{
list.Add(new Tuple<int, int>(x, y));
}
}
Then you can add an element using this code:
list.Add(1, 2);
To access the items:
var listItem = list[0]; // first item of list
int value = listItem.Item2; // second "column" of the item
You can go with dictionary also if you have a key value pair:
static void Main()
{
Dictionary<int, int> dictionary =
new Dictionary<int, int>();
dictionary.Add(0,3);
dictionary.Add(1,8);
dictionary.Add(2, 13);
dictionary.Add(3, -1);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With