Does anyone help me convert vb.net to c#

  • Thread starter Thread starter Alan Ho
  • Start date Start date
A

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
 
Alan Ho said:
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.
 
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



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.
 
Back
Top