Is there any semantic difference between
ToXXXX
conversion methods andAsXXXX
conversion methods in the .NET framework?Examples of such methods are
Object.ToString
andEnumerable.AsEnumerable<T>
.If no: Are there still recommendations when to name a conversion method
AsXXXX
and when to name itToXXXX
?If yes: Is there a .NET framework design guideline / FxCop style rule for this?
views:
60answers:
1
+12
A:
If method returns the same instance but casted to another type, use AsXXX method. If method consntructs new instance of unrelated type using object data, use ToXXX method.
STO
2010-07-03 20:47:35
The same thing has been mentioned in the book "Linq in Action".
devcoder
2010-07-03 22:19:32