Why is OfType<> faster than Cast<>?

后端 未结 4 1921
猫巷女王i
猫巷女王i 2020-12-15 03:39

In answer to the following question: How to convert MatchCollection to string array

Given The two Linq expressions:

var arr = Regex.Matches(strText,          


        
4条回答
  •  無奈伤痛
    2020-12-15 04:26

    Actually isof() first checks the type and then casts it, where as cast() just does the 2nd part. So obviously isof() will be slower than direct casting

    http://codenets.blogspot.in/2010/06/cast-vs-oftype.html

提交回复
热议问题