tag:blogger.com,1999:blog-1194836729866470946.post7408256873673077901..comments2024-03-23T08:53:17.893-04:00Comments on Pranay Rana: Extende Array Class with Extension methodpranay ranahttp://www.blogger.com/profile/01998269478315143789noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-1194836729866470946.post-26327152698857858982012-05-15T07:33:04.917-04:002012-05-15T07:33:04.917-04:00A better type-safe less complicated version..
...A better type-safe less complicated version..<br /><br /> public static float Average(this IEnumerable numbers)<br /> {<br /> return (float)numbers.Sum() / numbers.Count();<br /> }Ruchit S.http://www.ruchitsurati.netnoreply@blogger.comtag:blogger.com,1999:blog-1194836729866470946.post-83074882814654472972012-05-15T07:20:37.999-04:002012-05-15T07:20:37.999-04:00This is wrong design with many loopholes. Your Ext...This is wrong design with many loopholes. Your Extension method must explicitly mention that it is only for int[]. And if it is meant to work for int[] then there's no point in making it around Array type. Remember, your code is not just supposed to do the work, It is supposed to work for other programmers. Ask yourself these question and come up with better version of the same method.<br /><br /><br />1.) What the extension is supposed to do ? Functional specs of the method.<br /><br />2.) Why do you want to make it as an Extension method ?<br /><br />3.) What purpose will it serve for other programmers ? In other words, what is the intended use of the Extension method ?<br /><br />4.) Type safety ?? General compatibility ??<br /><br />5.) What part of your personal code library will it belong to ?<br /><br />Hope you'll take this positively and publish a better version.<br /><br /> - Ruchit.Ruchit S.http://www.ruchitsurati.netnoreply@blogger.com