简体   繁体   English

如何在c#中将两个值连接到文本框中?

[英]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. 我需要在文本框中输出02:00格式。 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! 看来你正在使用C#像sql语法!

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 小提琴链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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