Solved

Converting VP.NET to C#

Posted on 2009-04-12
4
472 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:chezbrgrs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:chezbrgrs
ID: 24127462
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

0
 
LVL 18

Accepted Solution

by:
philipjonathan earned 500 total points
ID: 24127885
Yes, I believe you got it correctly translated.

Another way to do that:

string s = _dstMemberData.Tables[(int) MEMBER_DATA_TABLES.MEMBER_PROFILE_INFO_DATA].Rows[0]["LastLoginDate"].ToString().Trim()
DateTime _dtmLastActivityDate = DateTime.MinValue;
try
{
  _dtmLastActivityDate = DateTime.Parse(s);
}
catch
{
}
0
 
LVL 11

Expert Comment

by:Vivek Thangaswamy
ID: 24128078
Hope this converter also helps you
http://www.developerfusion.com/tools/convert/vb-to-csharp/
 
0
 

Author Closing Comment

by:chezbrgrs
ID: 31569385
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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question