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

  • SEARCH
  • Home
  • 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 432373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:04:05+00:00 2026-05-12T20:04:05+00:00

Why won’t this work? public static int[] GetListOfAllDaysForMonths() { static int[] MonthDays = new

  • 0

Why won’t this work?

public static int[] GetListOfAllDaysForMonths()
{
    static int[] MonthDays = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};

    return MonthDays;
}

I had to move the variable declaration outside of the method:

    static int[] MonthDays = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
public static int[] GetListOfAllDaysForMonths()
{
    return MonthDays;
}

Also, so by creating it this way, we only have one instance of this array floating around in memory? This method sits inside a static class.

  • 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-05-12T20:04:05+00:00Added an answer on May 12, 2026 at 8:04 pm

    C# doesn’t support static locals at all. Anything static needs to be a member of a type or a type itself (ie, static class).

    Btw, VB.Net does have support for static locals, but it’s accomplished by re-writing your code at compile time to move the variable to the type level (and lock the initial assignment with the Monitor class for basic thread safety).

    [post-accept addendum]
    Personally, your code sample looks meaningless to me unless you tie it to a real month. I’d do something like this:

    public static IEnumerable<DateTime> GetDaysInMonth(DateTime d)
    {
        d = new DateTime(d.Year, d.Month, 1);
        return Enumerable.Range(0, DateTime.DaysInMonth(d.Year, d.Month))
                 .Select(i => d.AddDays(i) );
    }
    

    Note also that I’m not using an array. Arrays should be avoided in .Net, unless you really know why you’re using an array instead of something else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

why won't this work? function login(){ if(window.XMLHttpRequest){ ajax=new XMLHttpRequest(); }else if(window.ActiveXObject){ ajax=new ActiveXObject(Microsoft.XMLHTTP); }
This won't compile: namespace Constructor0Args { class Base { public Base(int x) { }
Why won't this simple subtraction work? int MyPageNumber = Convert.ToInt32(cboPageNumber.SelectedItem); MyPageNumber += (MyPageNumber -
Why won't this work? View1 loads View2. In view2: - (void) goToView { View3
This code won't compile because there is an illegal reference to a static field.
Why won't this work? void RatingWidget::mouseDoubleClickEvent(QMouseEvent * e) { this->setEnabled(!this->Enabled); } // I also
Why won't the following code work? class parent {} class kid:parent {} List<parent> parents=new
Why won't this work in Oracle? Is there a way to make this work?
This just won't work. The problem is that I do not know enough to
Why won't this work in Safari? <script language=javascript type=text/javascript> function changeUrl(url) { window.location.href='http://google.com'; return

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.