Click here to Skip to main content
15,908,020 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
123
456
abc
def

I have used list<string> variable .I should insert abc after 123 and def after 456 not using at specific index like list1.Insert(); .It should be generic.How can i do this
Posted
Comments
Christian Graus 6-Jul-11 3:37am    
How does it matter ? He's creating a list. I HATE when people tag ASP.NET, but their question is generic C#.
Sergey Alexandrovich Kryukov 6-Jul-11 3:39am    
You're right, of course. I did not pay attention, thought it was about UI control... removed.
--SA
myes 6-Jul-11 4:28am    
I specified tag to be C# only

1 solution

'Generic' means using generics, as in List<int>. With a generic List, Insert takes the index where you insert, just as you said. So, what is the issue ? If you were using ArrayList, the old non generic class, the same method exists. So, either there is no issue, or you need to explain better.
 
Share this answer
 
v2
Comments
myes 6-Jul-11 3:39am    
Sorry generic means it should be general way of inserting not using .Net framework list1.Insert().Because the range of data will go long like example 123,456,678,901,abc,def,ghi,jkl,................means it should be sorted to 123,abc,456,def,678,ghi,............
Sergey Alexandrovich Kryukov 6-Jul-11 3:40am    
Sorry, sounds like a gibberish to me. Are you using List<> or not? If you're using List<>, it has well-defined set of operations, that's it. I don't understand how can it ever be a problem.
--SA
Sergey Alexandrovich Kryukov 6-Jul-11 3:39am    
Correct, my 5.
--SA
Christian Graus 6-Jul-11 3:41am    
If you're not using the .NET framework, you're not using C#. Perhaps you need to edit your post to explain it better. Do you mean you want to write your own list class ? What class exactly are you using, and what is your issue ? do you mean you want your data to automatically sort according to some arbitrary rule that you will define ? you can define a sort method for that.
myes 6-Jul-11 4:27am    
Sorry again .iam saying if i use list1.insert i should specify index that specific should not be used .index should not be specified iam having list<string> of 123, 456,789,..... iam adding string such as abc,def,ghi.... now the list is such that 123,456,789,abc,def,ghi...now i need to get 123,abc,456,def,789,ghi is there a possibility to insert in these way without using list.insert at specific index.i guess this comment is more readable

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