PC Review


Reply
Thread Tools Rate Thread

c# - Fastest way to initialise a numeric array

 
 
=?Utf-8?B?c3RldmU=?=
Guest
Posts: n/a
 
      27th Sep 2005
I want to set all elements in a numeric array to a value other than 0.
The default numeric initialisers set the elements to 0.
Is looped assignment the fastest way, or is there an equivalent to the C RTL
memset.

Cheers

Steve
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Um9u?=
Guest
Posts: n/a
 
      27th Sep 2005
You can do this:

int[] numbers = new int[]{1,2,3,4,5,6,7,8,9};

"steve" wrote:

> I want to set all elements in a numeric array to a value other than 0.
> The default numeric initialisers set the elements to 0.
> Is looped assignment the fastest way, or is there an equivalent to the C RTL
> memset.
>
> Cheers
>
> Steve

 
Reply With Quote
 
=?Utf-8?B?c3RldmU=?=
Guest
Posts: n/a
 
      27th Sep 2005
Thanks Ron,

But I have a rather large number of elements, and I don't really want to
clutter code-space with a constant initialise.

Ciao

Steve

"Ron" wrote:

> You can do this:
>
> int[] numbers = new int[]{1,2,3,4,5,6,7,8,9};
>
> "steve" wrote:
>
> > I want to set all elements in a numeric array to a value other than 0.
> > The default numeric initialisers set the elements to 0.
> > Is looped assignment the fastest way, or is there an equivalent to the C RTL
> > memset.
> >
> > Cheers
> >
> > Steve

 
Reply With Quote
 
Peter Rilling
Guest
Posts: n/a
 
      27th Sep 2005
You might have to loop through the elements. If you need to instantiate the
same array multiple times, you might want to create an instance when the app
starts and then just copy/clone the array as you need it.

"steve" <(E-Mail Removed)> wrote in message
news:CE4B35C0-CB7C-4952-9662-(E-Mail Removed)...
> Thanks Ron,
>
> But I have a rather large number of elements, and I don't really want to
> clutter code-space with a constant initialise.
>
> Ciao
>
> Steve
>
> "Ron" wrote:
>
>> You can do this:
>>
>> int[] numbers = new int[]{1,2,3,4,5,6,7,8,9};
>>
>> "steve" wrote:
>>
>> > I want to set all elements in a numeric array to a value other than 0.
>> > The default numeric initialisers set the elements to 0.
>> > Is looped assignment the fastest way, or is there an equivalent to the
>> > C RTL
>> > memset.
>> >
>> > Cheers
>> >
>> > Steve



 
Reply With Quote
 
shiv_koirala@yahoo.com
Guest
Posts: n/a
 
      27th Sep 2005
Create once the object and then clone it using
either serialization or .clone

-------
Regards ,
C#, VB.NET , SQL SERVER , UML , DESIGN Patterns Interview question book
http://www.geocities.com/dotnetinterviews/
My Interview Blog
http://spaces.msn.com/members/dotnetinterviews/

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialise the registry values in a array and retrive the values asrequired Subodh Microsoft Excel Programming 1 26th Apr 2010 05:11 AM
Fastest way to reset to zero an array Charles Microsoft Excel Programming 10 5th Sep 2007 12:00 PM
fastest way to add array elements to list Bob Microsoft C# .NET 4 31st Aug 2007 04:28 AM
Fastest way to pass large array to and from COM apm Microsoft C# .NET 5 19th Sep 2005 12:55 PM
How to Initialise a Structure Array in a Dim Statement Charles Law Microsoft VB .NET 2 13th Dec 2004 03:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:37 AM.