Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between `ToXXXX` and `AsXXXX` conversion methods?

Is there any semantic difference between ToXXXX conversion methods and AsXXXX conversion methods in the .NET framework?

Examples of such methods are Object.ToString and Enumerable.AsEnumerable<T>.

like image 603
stakx - no longer contributing Avatar asked Jul 03 '10 20:07

stakx - no longer contributing


1 Answers

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.

like image 64
STO Avatar answered Nov 10 '22 13:11

STO