问题描述
我有以下代码。在salesOrderDto中,我有一个名为SalesOrder的变量,其值为0(我不太确定其数据类型)。如何将SalesOrder的值转换为空字符串?以下是我的代码:
Hi, I have the following codes. Inside the salesOrderDto I have a variable called SalesOrder which value is 0(I am not quite sure of its data type). How can I convert the value of SalesOrder into a empty string? Below are my codes:
using (IDataReader dataReader = db.ExecuteReader(selectCommand))
{
if (dataReader.Read())
{
salesOrderDto = ParseDto<SalesOrderDto>(dataReader);
}
}
if (salesOrderDto.SalesOrder == 0)
{
//convert here
//i have tried below method but the result is not what i want
salesOrderDto.SalesOrder.ToString(" ");
salesOrderDto.SalesOrderGroup.ToString(" ");
}
推荐答案
如何将SalesOrder的值转换为空字符串?
How can I convert the value of SalesOrder into a empty string?
当你调用ToString方法时,它只返回字符串值而不更新它,你需要的是设置一个字段或属性的值,所以你可以这样做
when you call ToString method, it only return string value not updating it, what you need is set the value of a field or property, so you can do as below
salesOrderDto.SalesOrder ="";
但是除了字符串以外,当SalesOrder还有其他类型时,上面的行会失败。
but above line will fail when you have some other type for SalesOrder other than string.
这篇关于将DTO对象值转换为String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!