Home All Groups Group Topic Archive Search About

Does anyone help me convert vb.net to c#

Author
2 Apr 2005 12:35 PM
Alan Ho
Function Helper(ByVal obj As Object) As String
        Dim thisDate As Date = CDate(obj)
        Return WeekdayName(Weekday(thisDate, vbSunday), False, vbSunday) &
"<br>" & _
            thisDate.Day & "/" & thisDate.Month
End Function



(I can't find any method call Date, WeekdayName and CDate in C#. What can i
do?)
Thanks

Author
2 Apr 2005 12:52 PM
Herfried K. Wagner [MVP]
"Alan Ho" <gto_stat***@yahoo.com.hk> schrieb:
> Function Helper(ByVal obj As Object) As String
>        Dim thisDate As Date = CDate(obj)
>        Return WeekdayName(Weekday(thisDate, vbSunday), False, vbSunday) &
> "<br>" & _
>            thisDate.Day & "/" & thisDate.Month
> End Function
>
>
>
> (I can't find any method call Date, WeekdayName and CDate in C#. What can
> i
> do?)

Although your question is off-topic here:

'Date' -> 'DateTime'.  In order to use functions like 'Weekday' and
'WeekdayName' add a reference to "Microsoft.VisualBasic.dll" and import
'Microsoft.VisualBasic.DateAndTime'.  Instead of 'CDate' use
'DateTime.Parse'/'DateTime.ParseExact' or similar.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
4 Apr 2005 1:23 PM
Samuel R. Neff
Why would you import the Microsoft.VisualBasic namespace into C# for
functionality that is very readily available natively as part of the
..NET class library?

using System;

public class DateTest
{
  public static void Test()
  {
    Console.WriteLine(MyDateFormat(DateTime.Now));
    Console.WriteLine(MyDateFormat("1/1"));
  }

  public static string MyDateFormat(object obj)
  {
    DateTime d;
    if (obj is DateTime)
    {
      d = (DateTime)obj;
    }
    else if (obj is string)
    {
      d = DateTime.Parse((string)obj);
    }
    else
    {
      throw new ArgumentException(obj.GetType().FullName + " no valid
for Format");
    }

    return d.ToString("dddd") + "<br>" + d.ToString("d/m");
  }
}

Sam



On Sat, 2 Apr 2005 14:52:48 +0200, "Herfried K. Wagner [MVP]"
<hirf-spam-me-here@gmx.at> wrote:

Show quoteHide quote
>"Alan Ho" <gto_stat***@yahoo.com.hk> schrieb:
>> Function Helper(ByVal obj As Object) As String
>>        Dim thisDate As Date = CDate(obj)
>>        Return WeekdayName(Weekday(thisDate, vbSunday), False, vbSunday) &
>> "<br>" & _
>>            thisDate.Day & "/" & thisDate.Month
>> End Function
>>
>>
>>
>> (I can't find any method call Date, WeekdayName and CDate in C#. What can
>> i
>> do?)
>
>Although your question is off-topic here:
>
>'Date' -> 'DateTime'.  In order to use functions like 'Weekday' and
>'WeekdayName' add a reference to "Microsoft.VisualBasic.dll" and import
>'Microsoft.VisualBasic.DateAndTime'.  Instead of 'CDate' use
>'DateTime.Parse'/'DateTime.ParseExact' or similar.

B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position. 
Seaking mid to senior level developer.  For
information or to apply e-mail resume to
sam_blinex_com.