i am new in C# language, i am trying to create a new desktop app.
but i am confuse to create a string like this..
private string getResult(int x){
string results = "";
return results
}
so when i use getResult(1)
, it will return 0001
if i use getResults(111)
, it will return 0111
if i use getResults(10)
, it will return 0010
.
something like this, i am confuse to create a string like this.
You can simple use ToString
with parameter:
private string getResult(int x)
{
return x.ToString("0000");
}
from @Dmitry Bychenko :
You can also use "D4"
as parameter instead of "0000"
with same results.
This solution also works with negative numbers instead of PadLeft
method.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments