Link to home
Start Free TrialLog in
Avatar of chezbrgrs
chezbrgrsFlag for United States of America

asked on

Converting VP.NET to C#

Hello Experts -

I am converting some VB.NET code to C#.  Can someone please help me with the following block of code?
With _dstMemberData.Tables(MEMBER_DATA_TABLES.MEMBER_ACCOUNT).Rows(0) _
        _dtmLastActivity = IIf(IsDate(.Item("LastLoginDate").ToString().Trim()), _
        .Item("LastLoginDate").ToString().Trim(), DateTime.MinValue)
End With

Open in new window

Avatar of chezbrgrs
chezbrgrs
Flag of United States of America image

ASKER

Quick addition to the question...Does the following equal the same thing as above?

I also added the new IsDate method.

if (IsDate(_dstMemberData.Tables[(int)MEMBER_DATA_TABLES.MEMBER_PROFILE_INFO_DATA].Rows[0]
    ["LastLoginDate"].ToString().Trim()))
        _dtmLastActivityDate = 
            Convert.ToDateTime(_dstMemberData.Tables[(int)MEMBER_DATA_TABLES.MEMBER_PROFILE_INFO_DATA]
                .Rows[0]["LastLoginDate"].ToString().Trim()); 
else
    _dtmLastActivityDate = DateTime.MinValue;
 
// Method equivalent to IsDate in VB.NET
public static bool IsDate(object Expression)
    {
        string strDate = Expression.ToString();
        try
        {
            DateTime dt = DateTime.Parse(strDate);
            if (dt != DateTime.MinValue && dt != DateTime.MaxValue)
                return true;
            return false;
        }
        catch
        {
            return false;
        }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of philipjonathan
philipjonathan
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your time.

I had also tried the converter in the comment below but I found it included keywords that were not in C#.  For example, it listed _dstMemberData.Tables[(int)MEMBER_DATA_TABLES.MEMBER_PROFILE_INFO_DATA].Rows[0].Item["LastLoginDate"]...

From what I've found, '.Item' does not exist in the C# context.