简体   繁体   中英

How to concatenate two values into text box in c#?

I have two values, I want to cast these values into a text box. The way I tried is mentioned below

 string time="00";
 int Result ="02";
 textresult.Text=result+' '+time;//first way error result
 textresult.Text=(CAST(Result AS varchar(50))+' '+CAST(time AS varchar(50)))//second way..syntax error.

I need output as 02:00 format in text box. Please suggest a way to solve this????

Try below.

textresult.Text=string.Format("{0}:{1}",Result.ToString("D2"),time);

Your code reports syntax error because there is. It seems you are using C# like sql syntax!

Try this:-

string time = "00";
int Result = 02;
textresult.Text=Result.ToString("D2") + ":" + time;

This might help.

string time="00";
int Result =02;

textresult.Text = String.Format("{0}:{1}",Result.ToString("D2"),time);

Fiddle link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM