I'm looking for some tips for writing some stream-optimized, optimized, and elegant code to do the following:
I want the static method to return a sequence of integers. So, for example, the application starts, thread 1 calls the GetSequence method and says that it wants to accept 3, so it gets an integer array consisting of 0,1,2. Then thread 2 calls the method and says βgive me 4β, so it returns 3,4,5,6. Multiple threads can simultaneously call this method.
To give an idea of ββwhat I'm thinking about, here is my attempt:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SequenceNumberService { class Program { static void Main(string[] args) { int[] numbers = NumberSequenceService.GetSequence(3); foreach (var item in numbers) { Console.WriteLine(item.ToString()); }
My questions: Am I best suited to this, or is there any other way to achieve this? Any suggestions for optimizing this code?
Thanks so much for any help.
source share