I have a code that looks like this:
int A = 3; int B = 5; List<int> TheList = new List<int>(); TheList.Add(A); TheList.Add(B); SomeFunction(TheList);
Is there a way to write something like this:
SomeFunction((A,B).ToList());
Yes:
new List<int>{A, B}
creates a list with the two elements you specify. You can pass this list to a function or do something else with it.
Note that if your target function accepts IList<int> rather than List<int> , you can shorten the syntax a bit by sending a new array from int s because the T[] arrays implement their corresponding IList<T> interface.
IList<int>
List<int>
int
T[]
IList<T>
SomeFunction(new List<int> { A, B });
Source: https://habr.com/ru/post/1440194/More articles:Preventing a page from navigating at the top when a link is clicked - htmlCreating a Recently Viewed List, MySQL or Redis - phpHow to implement a single SQL transaction for multiple ObjectContext objects in EF4 - c #Visually Display Algorithm Flow - javaHttpPost on Android - unrecognized characters - androidMobile jquery page options - jqueryDefine authorization areas for a given Github token - githubcopying a list of common lisp structures - listThe variable in MediaWiki for the current user is mediawiki-templateswhat is a good editor besides eclipse for printing clojure code? - clojureAll Articles