无法将var设置为字符串,始终为null [英] Cannot set a var to a string, always null

查看:86
本文介绍了无法将var设置为字符串,始终为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个很奇怪的问题,即可以将一个字符串变量初始化为一个空字符串,然后将其设置为另一个字符串值.但是,请尝试尝试此字符串变量将不接受另一个字符串值.这是我们的代码

var shippingTo =";

如果(!string.IsNullOrWhiteSpace(request.ShippedTo))
{   //有订单
   如果(!string.IsNullOrEmpty(_order?))
    {
       shipToTo = _order.ClientCode;
    }
}

我们设置了变量,没问题&检查它是否显示为空字符串:

var shippingTo =";

已检查订单,其中clientCode设置为"AAA123".

但是,当我们这样做时,shippedTo始终为空,从不"AAA123".

shippedTo = _order.clientCode;

我们无法弄清楚为什么shipsTo总是为空& ;;永远不要设置为clientCode.

_order对象是通过数据协定从REST调用接收到的对象.

有人以前遇到过这种问题吗?

解决方案

您可以在C#中发布相关的REST json对象和数据协定吗? blockquote>

We have a very weird issue, where by a string variable can be initialised as an empty string then set to another string value.  However, try as we might this string variable will not accept another string value. This is our code

var shippedTo = "";

if (!string.IsNullOrWhiteSpace(request.ShippedTo))
{   // has an order
    if (!string.IsNullOrEmpty(_order?))
    {
        shippedTo = _order.ClientCode;
    }
}

We setup the variable, no problem & inspect it shows as an empty string:

var shippedTo = "";

The order is inspected is there, with the clientCode which is set to "AAA123".

However, when we do then shippedTo is always null, never "AAA123".

shippedTo = _order.clientCode;

We cannot figure out why shippedTo is always null & never set to the clientCode. 

The _order object is an object received from a REST call as mapped out via a data contract.

Anybody come across this kind of issue before?

解决方案

Could you post the relevant REST json object and your data contract in c#?


这篇关于无法将var设置为字符串,始终为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆