In C#, How do I call a function that is returning a list?
static void Main(string[] args)
{
List<string> range = new List<string>();
range.ForEach(item => item.WildcardFiles()); //this is not working
}
List<string> WildcardFiles(string first)
{
List<string> listRange = new List<string>();
listRange.Add("q");
listRange.Add("s");
return listRange;
}
<< is the left shift operator. It is shifting the number 1 to the left 0 bits, which is equivalent to the number 1 .
%d is a format specifier, used in C Language. Now a format specifier is indicated by a % (percentage symbol) before the letter describing it. In simple words, a format specifier tells us the type of data to store and print. Now, %d represents the signed decimal integer.
There are various things wrong with your code:
ForEach
on it. That's not going to do anything.WildcardFiles
on a string, when it's not a method of string.WildcardFiles
which is an instance method in whatever your declaring type is, but without any instances of that type.WildcardFiles
without passing in an argument for the first
parameterWildcardFiles
WildcardFiles
ignores its parameterNow I suspect you really wanted something like:
static void Main(string[] args)
{
List<string> range = WildcardFiles();
foreach (string item in range)
{
// Do something with item
}
}
static List<string> WildcardFiles()
{
List<string> listRange = new List<string>();
listRange.Add("q");
listRange.Add("s");
return listRange;
}
I don't know what exactly you want but currently you should do:
range.ForEach(item => WildcardFiles(item));
and make your method static to work.
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