Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8797341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:50:09+00:00 2026-06-13T23:50:09+00:00

Can anyone please explain, why private readonly Int32[] _array = new[] {8, 7, 5};

  • 0

Can anyone please explain, why private readonly Int32[] _array = new[] {8, 7, 5}; can be null?

In this example, it works, and _array is always not null. But in my corporate code I have a similar code and _array is always null. So I forced to declared it as static.

The Class is a partial Proxy Class from my WCF Contract.

using System;
using System.ComponentModel;

namespace NullProblem
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var myClass = new MyClass();

            // Null Exception in coperate code
            int first = myClass.First;
            // Works
            int firstStatic = myClass.FirstStatic;
        }
    }

    // My partial implemantation
    public partial class MyClass
    {
        private readonly Int32[] _array = new[] {8, 7, 5};
        private static readonly Int32[] _arrayStatic = new[] {8, 7, 5};

        public int First
        {
            get { return _array[0]; }
        }

        public int FirstStatic
        {
            get { return _arrayStatic[0]; }
        }
    }

    // from WebService Reference.cs
    public partial class MyClass : INotifyPropertyChanged 
    {
        // a lot of Stuff

        #region Implementation of INotifyPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:50:10+00:00Added an answer on June 13, 2026 at 11:50 pm

    WCF does not run the constructor (which includes the field initializer), so any objects created by WCF will have that null. You can use a serialization callback to initialize any other fields you need. In particular, [OnDeserializing]:

    [OnDeserializing]
    private void InitFields(StreamingContext context)
    {
        if(_array == null) _array = new[] {8, 7, 5};
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can anyone please explain how this works (asz + 7) & ~7; It rounds
Can anyone please explain this code? This example is taken from javascript.info. I don't
Can anyone please explain to me how this works: <?php print 5 . print
Can anyone please explain how this line works. a & 3 || (b, c)
Can anyone please explain me what delegateEvents in backbone.js does? The documentation did not
Can anyone please explain me how silverlight code gets executed.For example in asp.net if
Can anyone please explain me why this code does what it does. What I
Can anyone please explain what is the meaning of this code for ARM? __asm__
I am new to perl. Can anyone please explain the meaning of // operator
Can anyone please explain exactly what this code and its components are doing? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.