|
-
Mar 11th, 2013, 05:30 PM
#1
Thread Starter
Lively Member
[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.
-
Mar 11th, 2013, 06:51 PM
#2
Thread Starter
Lively Member
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);
-
Mar 12th, 2013, 11:51 AM
#3
Hyperactive Member
Re: [RESOLVED] Storing DateTime settings in a class?
-
Mar 12th, 2013, 03:13 PM
#4
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|