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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:25:13+00:00 2026-05-24T16:25:13+00:00

I have this class: public class CalendarData_Day { public DateTime Date { get; set;

  • 0

I have this class:

public class CalendarData_Day
{
    public DateTime Date { get; set; }
    public DayType TypeOfDay { get; set; }
    public bool Choose { get; set; }

    public CalendarData_Day(DateTime datum) : this(datum, DayType.Normal, true)
    {
    }

    public CalendarData_Day(DateTime datum, DayType typDne) : this(datum, typDne, true)
    {
    }

    public CalendarData_Day(DateTime datum, DayType typDne, bool vybran)
    {
        this.Date = datum;
        this.TypeOfDay = typDne;
        this.Choose = vybran;
    }
}

and I want in second constructor check if DayType is Weekend and if it is then not send to Choose true but false. Anybody knows how can I do it?
I know I can add to last constructor if and checked but it doesn´t seem right for me. I think there is better way I think that I should do it other way or is this in last contructor okay:

if (TypeOfDay == DayType.Weekend)
    this.Choose = false;

I know it´s working but I don´t know it is right way.

Edit:
I am sorry for that I don´t explained everything. There is more than 2 DayTypes, lets say there is Holiday, Work, … And I want that user can call class with just second constructor and if DayType would be Weekend or Holiday then Choose must be false but if it would be Normal or Work it should be true or user must user last contructor and set DayType to Work and Choose to false. It is complicated I am sorry I should wrote this first time.

  • 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-24T16:25:14+00:00Added an answer on May 24, 2026 at 4:25 pm

    It would be nicer to pass the chained constructor argument based on the parameter:

    public CalendarData_Day(DateTime datum, DayType typDne)
        : this(datum, typDne, typeDne != DayType.Weekend)
    {        
    }
    

    That way you don’t need to set the property twice – once to a sort of default value and then fix it based on information you already knew.

    I would personally change the parameter name from typDne to dayType or something similar.

    EDIT: I’ve only just seen that you were considering putting your test into the last constructor rather than the second one. I would expect the value given by the caller for vybran to be accepted as-is, rather than conditionally ignored. You only describe wanting the second constructor to check for DayType == Weekend – not the last constructor – so it’s only the second constructor that should change.

    EDIT: If Choose must be false for Weekend or Holiday then I would enforce that in the last constructor but pick the value in the second constructor:

    public CalendarData_Day(DateTime datum, DayType typDne)
        : this(datum, typDne,
               typeDne != DayType.Weekend && typeDne != DayType.Holiday)
    {        
    }
    
    public CalendarData_Day(DateTime datum, DayType typDne, bool vybran)
    {
        if (vybran && (typeDne == DayType.Weekend || typeDne == DayType.Holiday))
        {
            throw new ArgumentException(
               "vybran cannot be true for holiday or weekend dates", "vybran");
        }
        this.Date = datum;
        this.TypeOfDay = typDne;
        this.Choose = vybran;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class. public class Foo { public Guid Id { get; set;
I have this class: public class StatInfo { public string contact; public DateTime date;
I have this class and table: public class Foo { public Guid Id {get;set;}
I have this class called Table: class Table { public string Name { get
I have this class public class Address:Entity { public virtual string Address1 { get;
This is probably not possible, but I have this class: public class Metadata<DataType> where
I have this method in my db class public function query($queryString) { if (!$this->_connected)
I have some classes layed out like this class A { public virtual void
I have a class like this: public class Stretcher : Panel { public static
I have a class like this: public class myClass { public List<myOtherClass> anewlist =

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.