Hi,
I am new to programming in C#. Now, I am struck with a logic.
I have a set of date fields (DateTime picker controls) . I need to find out the least date in those date fields.
I tried the following logic.
for (i=1; i < 20; ++i)
{
int j=i+1;
string Field1 = tdField + i.ToString();
string Field2 = tdField + j.ToString();
DateTime TD, NTD;
min = DateTime.Now;
TD=Field1.ValueAsDateTime;
NTD=Field2.ValueAsDateTime;
if (TD < NTD)
{
min = TD;
TD = NTD;
return min;
}
}
MessageBox.Show(min.ToString());
This code is executing fine at runtime, but it is not giving me the correct least date. It is executing for 20 times (as mentioned in for loop) and it is giving me the least number in the 19th and 20th dates. I am sure this code will do like that only, but what is the change I need to do for getting the least date in the set of 20 dates.
I am really struck with this logic from 2 days.
I would appreciate any help in this regard.
Thanks