Variable Context Question

Posted by Soo on Stack Overflow See other posts from Stack Overflow or by Soo
Published on 2010-06-08T20:47:54Z Indexed on 2010/06/08 20:52 UTC
Read the original article Hit count: 360

Filed under:
|

In the following code snippet, if I leave out the line of code that is surrounded by the /////'s, I get an error that reads: "Use of unassigned local variable CurrentDate". It seems a bit silly for me to just give CurrentDate an arbitrary value, is there a better way around this?

DateTime CurrentDate;

///////////////////////////
CurrentDate = DateTime.Now;
///////////////////////////

if(1==1)
{
CurrentDate = DateTime.Now.AddDays(1);
}

if(CurrentDate == DateTime.Now)
{
...
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about datacontext