locked
Day of Week Change Text RRS feed

  • Question

  • How can I make sure that if it is Monday that the text indicates that it is Monday and if it is not Monday that the text indicates that it is not Monday?

    I use the following setup as indicated below, but I don't know what to declare as an if function (?????).

    private void chkAgenda_TextChanged(object sender, EventArgs e)
            {

                    if (?????)
                    {
                    chkAgenda.Text = No monday;
                    }

                    else
                    {
                    chkAgenda.Text = Monday;
                    }
            }    

    Monday, April 27, 2020 11:42 AM

Answers

  • For C# ==

    if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
    {
        
    }

    Also if you add the following using statement

    using static System.DateTime;

    We can write the statement as follows

    if (Now.DayOfWeek == DayOfWeek.Monday)
    {
    
    }


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Monday, April 27, 2020 12:08 PM

All replies

  • if DateTime.Now.DayOfWeek = DayOfWeek.Monday then
    Monday, April 27, 2020 11:50 AM
  • When I do what you say I get the following error:

    Property or indexer 'DateTime.DayOfWeek' cannot be assigned to -- it is read only.

    Monday, April 27, 2020 12:00 PM
  • For C# ==

    if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
    {
        
    }

    Also if you add the following using statement

    using static System.DateTime;

    We can write the statement as follows

    if (Now.DayOfWeek == DayOfWeek.Monday)
    {
    
    }


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Monday, April 27, 2020 12:08 PM