Click here to Skip to main content
15,900,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
im using windows application in c#. i want to generate a sequence no in a text box. i used the code
IEnumerable<int32> var = Enumerable.Range(1,10);
textBox1.Text = var.ToString();
when i run the form i got " System.Linq.Enumerable+<rangeiterator>d__b1" this text in that text box. can u give me a proper solution.
Posted
Comments
[no name] 5-Sep-12 10:18am    
http://msdn.microsoft.com/en-us/library/system.linq.enumerable.range.aspx

Try:
C#
IEnumerable<int> var = Enumerable.Range(1, 10);
textBox1.Text = string.Join(",", var.ToArray());
 
Share this answer
 
Comments
CodeHawkz 5-Sep-12 12:00pm    
By far the most elegant solution :) string.Join is one method that's overlooked by many. My 5
Matt T Heffron 5-Sep-12 14:27pm    
...but I'd avoid using var as a variable name since it has its own c# meaning.
OriginalGriff 5-Sep-12 14:48pm    
So would I - I only used it to keep with his naming.
Try this :-

XML
IEnumerable<int> var = Enumerable.Range(1, 10);
            int[] Arr = var.ToArray();
            string Number="";
            for (int i = 0; i < Arr.Length; i++)
            {
                Number += Arr[i].ToString()+",";
            }
            textBox1.Text = Number;
 
Share this answer
 
Comments
CodeHawkz 5-Sep-12 12:02pm    
Don't use string concatenation for obvious reasons. Use a StringBuilder instead :)
Add a namespace of System.Linq /using System.Collections; to this page.
 
Share this answer
 
v2
Comments
vijkrnandini 5-Sep-12 10:21am    
i have added that namespace even then im getting the same
Kamalkant(kk) 5-Sep-12 10:21am    
using System.Collections;
vijkrnandini 5-Sep-12 10:23am    
ya its already there

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