www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Re: C# code sample

reply Kagamin <spam here.lot> writes:
pragma Wrote:

 Hi i come from a c# background
 
 I would like to write the following code in the according D style but i'm not
 sure howto do it
 
 c# code:
 void foo(IEnumerable<double[]> data)
 {
   foreach (var d in data)
   {
     do_some_stuff(d);
   }
 }
 
 i guess the D equivalent to IEnumerable is Range? how would it look like in D?

Usually there's a little need for a range in such case. IEnumerable is usually used because there's a high need for the List collection so it's used even more often than arrays. Current druntime heap implementation already gives D arrays C# List performance.
Jan 26 2011
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Kagamin:

 Current druntime heap implementation already gives D arrays C# List
performance.

What do you mean? Do you mean regarding appends, iteration, or what? Bye, bearophile
Jan 26 2011
prev sibling parent Jesse Phillips <jessekphillips+D gmail.com> writes:
Kagamin Wrote:

 pragma Wrote:
 
 i guess the D equivalent to IEnumerable is Range? how would it look like in D?

Usually there's a little need for a range in such case. IEnumerable is usually used because there's a high need for the List collection so it's used even more often than arrays. Current druntime heap implementation already gives D arrays C# List performance.

What? Of course there is a reason to use a Range/Iterable and has nothing to do with performance. He could be getting his double[] from any number of functions found in std.algorithm, most of whom return their own Range type.
Jan 26 2011