I have and old(ish) C# method I wrote that takes a number and converts it to any base:

```
string ConvertToBase(int number, char[] baseChars);
```

It's not all that super speedy and neat. Is there a good, known way of achieving this in .NET?

I'm looking for something that allows me to use **any** base with an arbitrary string of characters to use.

This only allows bases 16, 10, 8 and 2:

```
Convert.ToString(1, x);
```

I want to use this to achieve a massively high base taking advantage of numbers, all lower case and all upper case letters. Like in this thread, but for C# not JavaScript.

Does anyone know of a good and efficient way of doing this in C#?

`Convert.ToString`

can be used to convert a number to its equivalent string representation in a specified base.Example:

However, as pointed out by the comments,

`Convert.ToString`

only supports the following limited - but typically sufficient - set of bases: 2, 8, 10, or 16.## Update (to meet the requirement to convert to any base):

I'm not aware of any method in the BCL which is capable to convert numbers to any base so you would have to write your own small utility function. A simple sample would look like that (note that this surely can be made faster by replacing the string concatenation):

## Update 2 (Performance Improvement)

Using an array buffer instead of string concatenation to build the result string gives a performance improvement especially on large number (see method

`IntToStringFast`

). In the best case (i.e. the longest possible input) this method is roughly three times faster. However, for 1-digit numbers (i.e. 1-digit in the target base),`IntToString`

will be faster.