Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.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# Windows窗体中的十进制数/声明&;文本框使用_C#_Windows Forms Designer - Fatal编程技术网

C# Windows窗体中的十进制数/声明&;文本框使用

C# Windows窗体中的十进制数/声明&;文本框使用,c#,windows-forms-designer,C#,Windows Forms Designer,我对c#和编程比较陌生,因为一个项目,我开始使用windows窗体应用程序 我有带字符串和datatime类型的worker,但我不确定如何声明decimal,然后在文本框中使用它 我的testclass可以工作,但没有decimal internal class Customer { public string LastName { get; set; } public string FirstName { get; set; } public DateTime Bir

我对c#和编程比较陌生,因为一个项目,我开始使用windows窗体应用程序

我有带字符串和
datatime
类型的worker,但我不确定如何声明
decimal
,然后在
文本框中使用它

我的testclass可以工作,但没有
decimal

internal class Customer
{
    public string LastName { get; set; }
    public string FirstName { get; set; }
    public DateTime BirthDate { get; set; }

    public Customer(string lastName, string firstName, DateTime     birthDate)
    {
        LastName = lastName;
        FirstName = firstName;
        BirthDate = birthDate;
    }
}
在实际形式中,我使用一个
foreach
,第一列作为主项,然后下一列作为子项

var listViewItem = new   ListViewItem(customer.LastName);
listViewItem.SubItems.Add(customer.FirstName);
listViewItem.SubItems.Add(customer.BirthDate.ToShortDateString());
所以
string
非常简单,
datetime
得到了。
ToSortDateString()
,我该怎么处理这个该死的
十进制数呢

当我将项目添加到表单中时,我将其用于
按钮
单击
事件

string firstName = tbFirstName.Text;
string lastName = tbLastName.Text;
DateTime birthDate =     dtpBirthDate.Value;

var customer = new Customer(lastName, firstName, birthDate);
    _customers.Add(customer);
这里也是一样,
string
获取
.text
日期
获取
,但我真的不知道如何实现
十进制
:/


感谢并抱歉,如果结构不好,我正在打电话,试图复制代码片段。

在哪里使用十进制值。在类、窗体和单击按钮中基本上只声明了string和datetime。我遗漏了它,因为我甚至不知道如何正确地声明它(我想),因此我不能像其他人一样正确地使用它,所以我完全删除了它。这是我能访问的唯一版本,我试着到处寻找。我只在textbox中找到了有关验证的内容,但当您想从textbox(或一般的字符串)中获取十进制值时,我甚至无法使用它
public decimal Foo{get;set;}
Decimal.Parse
Decimal.TryParse
@Thoe332因此,您的问题是“如何将DateTimePicker中的值检索到类
Customer
的属性
BirthDate
?”不,如果我不能提出正确的问题,很抱歉。我有两个字符串和一个日期时间,我想添加一个小数点来使用它,因为我已经使用了其他字符串,但不知道如何使用。我想在foreach和button事件中使用十进制,但我不知道如何转换它