1

I want to remove all dependencies to Microsoft.VisualBasic from my solution.

One thing that causes me problems is the "Now" function.

Does anybody know what would be a clean solution for a replacement?

Thank you!

tmighty
  • 10,734
  • 21
  • 104
  • 218
  • 1
    What are you doing this? There are certain legacy holdovers to avoid from vb6, but other things in there are just part of the language. – Joel Coehoorn Mar 20 '14 at 20:33

2 Answers2

3

You can use DateTime.Now

Dim now As Date = Date.Now

It is a Shared property which means that you use it via classname without an instance.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • As `Date` is an alias to `DateTime` in VB (refs: [Date instead of DateTime?](http://stackoverflow.com/questions/5625795/date-instead-of-datetime), [Data Type Summary (Visual Basic)](http://msdn.microsoft.com/en-us/library/47zceaw7.aspx)) and the OP is apparently trying to avoid VB-specific things where possible, wasn't your original answer of `Dim now As DateTime = DateTime.Now` more in the spirit of what they want? – Andrew Morton Mar 20 '14 at 20:45
  • @AndrewMorton: he wants to avoid the `System.VisualBasic` namespace, he doesn't want to avoid VB.NET. I have always used `Date` instead of `DateTime` in VB.NET even if i have used Visual Basic very rarely. – Tim Schmelter Mar 20 '14 at 20:47
  • Fair enough, I just thought that maybe they wanted to go more directly to framework classes. – Andrew Morton Mar 20 '14 at 20:49
  • @AndrewMorton: it _is_ a framework class since it's actually `System.DateTime`. It would be the same as if you'd say that you should use `System.Int32` in C# instead of `int` or `System.String` instead of `string`. – Tim Schmelter Mar 20 '14 at 20:52
  • I find myself both agreeing and slightly disagreeing - maybe we can reasonably put it in the realm of "in-house styles" where both are in fact equally valid. – Andrew Morton Mar 20 '14 at 21:05
2

If you remove Microsoft.VisualBasic, you can use the Now property that is part of System.DateTime.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794