Runtime: Add concatenation method to int type

Created on 27 Apr 2019  路  4Comments  路  Source: dotnet/runtime

I'm not sure if this is the right place for this, but I have wanted to concatenate two integers into a new int many times, and while writing an extension method really isn't that much of a pain, but I think that this feature may have a place in .NET.

Instead of this:

int x = 1;
int y = 2;

Int.Parse(x.ToString() + y.ToString());

I usually use something like this:

int x = 1;
int y = 2;

x.Concat(y); // = 12

This method could be written so that a collection of ints may be passed as a parameter. I imagine that this feature addition would be welcome for many people (including myself!)

untriaged

Most helpful comment

If you're suggesting adding a new method to .Net Core, then following the API review process, the right place is the corefx repository.

Regarding the proposal itself: when is this operation actually useful?

All 4 comments

If you're suggesting adding a new method to .Net Core, then following the API review process, the right place is the corefx repository.

Regarding the proposal itself: when is this operation actually useful?

Thanks for pointing me towards the proper place!

As for when it's useful: I've used it in a couple of my projects and I just kinda assumed that this is relatively common, and that other people also use this in their work.

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@akmadian you can just write an extension method for that use-case
c# public static int Concat(this int first, int second) => (first * 10) + second;

Was this page helpful?
0 / 5 - 0 ratings