Results 1 to 4 of 4

Thread: [RESOLVED] Storing DateTime settings in a class?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    116

    Resolved [RESOLVED] Storing DateTime settings in a class?

    Hey guys,

    I thought I understood storing variables I will be calling frequently into classes down pat, but this just isn't playing nicely.

    Code:
    Class Paramaters
    {
    Public DateTime time = DateTime.Now;
    public string formatDate = "MM/dd";
    }
    The purpose is because I have a TON of if statements that will use this same call here and if I ever want to change it I don't want to have to go through each one to alter it. I know I can do it in a seperate class, but I am failing here. One thing I think my problem is, is that I am calling a class, within a class maybe? I don't see a way around this. Here is how I am trying to call it

    Code:
    private void Form1_Load(object sender, EventArgs e)
    {
    textBox1.Text = Parameters.time.ToString(Parameters.formatDate);
    }
    Seems too simple to be true. Thanks for the help.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    116

    Re: [RESOLVED] Storing DateTime settings in a class?

    Class:
    public static class Paramaters
    {
    public const string MonthDayFormat = "MM/dd";
    public static DateTime Time
    {
    get { return DateTime.Now; }
    }
    }

    Call:
    textBox1.Text = Paramaters.Time.ToString(Paramaters.MonthDayFormat);

  3. #3
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    259

    Re: [RESOLVED] Storing DateTime settings in a class?

    Edit

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2008
    Posts
    116

    Re: [RESOLVED] Storing DateTime settings in a class?

    I was in a pinch for time so I couldn't elaborate on why I resolved this. I was able to do what I describe why it is fixed.

    It now pulls my requirements from my helper class and displays it in real time as intended. I just had my layout very much incorrect. I'm all about having less code in my main form and dealing with multiple classes instead.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width