C# Windows窗体中的十进制数/声明&;文本框使用
我对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
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事件中使用十进制,但我不知道如何转换它