Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 向C类传递值的问题#_C# - Fatal编程技术网

C# 向C类传递值的问题#

C# 向C类传递值的问题#,c#,C#,时间是我试图将值传递给的类。(txtHour.Text、txtMin.Text)是值。我只是想把这些值传递给参数化构造函数。 我不完全确定它的语法是什么 Time time1; time1 = (txtHour.Text, txtMin.Text); ** 该方法似乎有效,除了我将其传递为int值,并且文本框的值被认为是字符串。当我对它们进行int解析时,它会说传递值的格式不正确。C#中的构造函数(通常)是通过使用new关键字结合类名(括号中的任何参数类似于方法调用)来调用的: Time ti

时间是我试图将值传递给的类。(txtHour.Text、txtMin.Text)是值。我只是想把这些值传递给参数化构造函数。 我不完全确定它的语法是什么

Time time1;
time1 = (txtHour.Text, txtMin.Text);
** 该方法似乎有效,除了我将其传递为int值,并且文本框的值被认为是字符串。当我对它们进行int解析时,它会说传递值的格式不正确。

C#中的构造函数(通常)是通过使用
new
关键字结合类名(括号中的任何参数类似于方法调用)来调用的:

Time time1 = new Time(txtHour.Text, txtMin.Text);

我还以为你会皈依基督教呢

Time time1 = new Time(
    Convert.ToInt32(txtHour.Text.Trim()), 
    Convert.ToInt32(txtMin.Text.Trim()));

非常正确-我只是演示如何进行构造函数调用。
Time time1 = new Time(
    Convert.ToInt32(txtHour.Text.Trim()), 
    Convert.ToInt32(txtMin.Text.Trim()));