Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return an array without creating a variable

Tags:

syntax

c#

.net

I have the following C# method:

private string[] test()
{
}

I would like to know if I can do something like this within the method:

return {"1","2"}

instead of:

string[] quantity = { "1","2" };
return quantity;

Kindly let me know how I can do this in C#.

like image 457
Derin Avatar asked Mar 15 '26 04:03

Derin


1 Answers

return new string[] { "1", "2" };
like image 126
cHao Avatar answered Mar 16 '26 18:03

cHao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!