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 6121551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:47:48+00:00 2026-05-23T15:47:48+00:00

Now I’ve long known and been use to this behavior in C#, and in

  • 0

Now I’ve long known and been use to this behavior in C#, and in general, I like it. But sometimes the compiler just isn’t smart enough.

I have a small piece of code where right now my workaround isn’t a big problem, but it could be in similar cases.

        bool gap=false;
        DateTime start; // = new DateTime();
        for (int i = 0; i < totaldays; i++)
        {
            if (gap)
            {
                if (list[i])
                {
                    var whgap = new WorkHistoryGap();
                    whgap.From = start; //unassigned variable error
                    whgap.To = dtFrom.AddDays(i);
                    return whgap;
                }
            }
            else
            {
                gap = true;
                start = dtFrom.AddDays(i);
            }
        }

The problem I’m seeing is what if you had to do this with a non-nullable struct that didn’t have a default constructor? Would there be anyway to workaround this if start wasn’t a simple DateTime object?

  • 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-23T15:47:48+00:00Added an answer on May 23, 2026 at 3:47 pm

    There is no such thing as a default constructor in a struct. Try it:

    struct MyStruct {
        public MyStruct() {
            // doesn't work
        }
    }
    

    You can have a static constructor, but you cannot define a default constructor for a struct. That’s why there’s the static method Create on so many structures, and why you can say new Point() instead of Point.Empty.

    The “default constructor” of any struct always initializes all of its fields to their default values. The Empty static field of certian types is for convenience. It actually makes zero difference in performance because they’re value types.

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

Sidebar

Related Questions

Now I know this basic question has been asked before, but I must be
Now i know there have been a lot of question about this, but i
Now I have a long query and I'd like to alternate with such a
Now this might sound simple, but I'm a bit mixed up. I am trying
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Now, this may be really stupid. But can we deploy a Java Swing Application
Now my folded lines look like this: +-- 123 lines: doSomeStuff();-------------------------- +-- 345 lines:
Now this is .NET but I am sure the principal should apply to all
Now I'm not sure if this is something I'm doing wrong, or something thats
Now facebook require to have these options when you want to use bulit-in actions

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.