none
Default Values Getting Assigned RRS feed

  • Question

  • Hi Team,

    when i am assigning Object to Object Like below

    a.id=b.id

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

    How can i Stop doing that ?



    Sujith

    Monday, February 4, 2019 7:14 AM

All replies

  • Hi sujith reddy komma,

    Thank you for posting here.

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

    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; }
        }

    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

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Stanly Fan Tuesday, February 5, 2019 2:52 AM
    Monday, February 4, 2019 7:28 AM
    Moderator
  • How about just declaring a.id as nullable integer? (i.e.: int?)
    Monday, February 4, 2019 7:45 AM
    Answerer