默认值获取分配 [英] Default Values Getting Assigned

查看:91
本文介绍了默认值获取分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Team,

当我将对象分配给对象时如下所示

when i am assigning Object to Object Like below

a.id = b.id

a.id=b.id

即使b.id不存在,a.id也会被评估为零。

even when b.id is not present a.id gets evaluated to Zero.

我怎么能停止这样做?




Sujith

推荐答案

嗨  sujith reddy komma,

感谢您在此发帖。

对于您的问题,如何定义a和b的ID?

For your question, how do you define the id of a and b?

根据我的理解,我做了一个简单的例子供参考。我用int。零是来自  值类型的默认值。

Based on my understanding, I make a simple example for reference. I use int. The zero is get from the default value of the Value type.

 class Program
    {

        static void Main(string[] args)
        {
            a.ID = b.ID;
        }
    }
    class a
    {
        public static int ID { get; set; }
    }
    class b
    {
        public static int ID { get; set; }
    }





有关值类型默认值的更多详细信息,请参阅MSDN文档。

For more details about the default of the value type, you could refer to the MSDN document.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/default-values-table

最诚挚的问候,

Wendy


这篇关于默认值获取分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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