|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Does anyone help me convert vb.net to c#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" <gto_stat***@yahoo.com.hk> schrieb: Although your question is off-topic here:> 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?) '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/> 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: B-Line is now hiring one Washington D.C. area VB.NET >> 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. developer for WinForms + WebServices position. Seaking mid to senior level developer. For information or to apply e-mail resume to sam_blinex_com. |
|||||||||||||||||||||||