Is there an inexpensive way to concatenate integers in csharp?
Example: 1039 & 7056 = 10397056
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you can find a situation where this is expensive enough to cause any concern, I’ll be very impressed:
Or, if you want it to be a little more “.NET-ish”:
int.Parse is not an expensive operation. Spend your time worrying about network I/O and O^N regexes.
Other notes: the overhead of instantiating StringBuilder means there’s no point if you’re only doing a few concatenations. And very importantly – if you are planning to turn this back into an integer, keep in mind it’s limited to ~2,000,000,000. Concatenating numbers gets very large very quickly, and possibly well beyond the capacity of a 32-bit int. (signed of course).