© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
8 replies
Tacti Tacoz

collection expression on Span<T>

Just a quick question, wasn't something like
void TestMethod(Span<int> span);

TestMethod([1]);

//Suppose to emit something like:
var _arg = 1;
TestMethod(new(&_arg, 1));
//Or
Span<int> span = stackalloc int[1];
span[0] = 1;
TestMethod(span);
void TestMethod(Span<int> span);

TestMethod([1]);

//Suppose to emit something like:
var _arg = 1;
TestMethod(new(&_arg, 1));
//Or
Span<int> span = stackalloc int[1];
span[0] = 1;
TestMethod(span);


Did they skip anti allocation improvements like this initially? right now it just allocates an array.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

how do stacks, lists, arrays, etc have a collection expression?
C#CC# / help
16mo ago
Convert Span<string> to Span<object>
C#CC# / help
3mo ago
✅ Issue with Collection Expression in the ubuntu-latest VM of Azure.
C#CC# / help
10mo ago
Span reverse not working on variable
C#CC# / help
8mo ago