Solved

Converting VP.NET to C#

Posted on 2009-04-12
4
474 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

691 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