如何从类中删除属性 [英] how to remove an attribute from a class

查看:98
本文介绍了如何从类中删除属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个名为Test的课程



Hi,
I have a class named Test

 public class Test
    {
        public string type { get; set; }
        public string self_url { get; set; }
        public string summary_url { get; set; }
        public string description { get; set; }
        public string location_description { get; set; }
        public List<object> images { get; set; }
        public string integration_id { get; set; }
        public bool realtime_server_url_is_public { get; set; }
        public string row_id { get; set; }
        public string auction_type { get; set; }
        public string last_updated { get; set; }
        public string time_start { get; set; }
}







我想删除row_id字段,如果它是空的。

我已经完成了以下代码,它只删除了内容。我想要的是如果它是空的那个row_id字段应该在类中看不到。



这里id是代码








And I want to remove the row_id field if it is empty.
I have done the below code and its only removing the contents. what I want is that the row_id field should not seen in the class if it is empty.

Here id is the code


Test lot=new Test();
if (lot.row_id  == "")
{
lot.row_id .Remove(0); 
}

推荐答案

要测试该字段是否未填充,您可以使用



To test if the field isn't populated you can use

if (!string.IsNullOrWhiteSpace(yourclass.row_id))





或将类型更改为string?,但这也可能涉及代码中的其他更改。



or change the type to "string?", but that will probably involve other changes in your code too.


这篇关于如何从类中删除属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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