Click here to Skip to main content
15,887,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir,

Could anyone please let me know how creating a series of numbers in C# without using for loop?

thanks Jai
Posted
Comments
Rockstar_ 14-May-12 2:19am    
You can use GoTo and If Conditions for this....
Rockstar_ 14-May-12 2:22am    
Otherwise u can use Recursive function and call the function repeatedly..
Sandeep Mewara 14-May-12 4:14am    
What series?

Hi,


This may help you...


C#
public static void PrintNext(i) {
    if (i <= 100) {
        Console.Write(i + " ");
        PrintNext(i + 1);
    }
}

public static void Main() {
    PrintNext(1);
}
 
Share this answer
 
Comments
JF2015 14-May-12 2:32am    
Nice one using Recursion! 5+
 
Share this answer
 
Comments
Mehdi Gholam 14-May-12 3:05am    
I like Enumerable.Range, 5'ed
Mohammad A Rahman 14-May-12 3:09am    
Thank you Mehdi :) Actually in the first link there is in depth discussion about the Range which might help the OP :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900