Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello All

Am here translating my VB code in C# but could not find the replacement of Simulate Keyword can anybody suggest me the solution.

Below is the VB Code

VB
If (Not IsDate(Request("start_date"))) or (Not IsDate(Request("end_date"))) Then
           result = False
       Else
           If CDate(Request("start_date")) > CDate(Request("end_date")) Then result = False
       End If



Below is the translated C# code

C#
if ((!Simulate.IsDate(Request("start_date"))) | (!Simulate.IsDate(Request("end_date"))))
{
           result = false;
       }
       else
       {
           if (Convert.ToDateTime(Request("start_date")) > Convert.ToDateTime(Request("end_date")))
           {
               result = false;
           }
       }


Error is :
if ((!Simulate.IsDate(Request("start_date"))) | (!Simulate.IsDate(Request("end_date"))))
The name 'Simulate' does not exists in current context.
Posted

Assuming that the Request returns a string, then use TryParse:
C#
DateTime start;
DateTime end;
if (!DateTime.TryParse(Request("start_date"), out start) || !DateTime.TryParse(Request("end_date"), out end))
   {
   result= false;
   }
else
   {
   if (start > end)
      {
      result = false;
      }
   }
 
Share this answer
 
Please see my past answer: Another SendKeys - Used in Citrix.[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900