2021年4月25日星期日

Creating an ordered (numbered) list in pure C#

I was just giving myself challenges to write pure C# codes for some HTML pages that I have. I was able to get through some of them with some online support (I am a newbie to C#) but now I am stuck with lists.

I want to replicate some ordered HTML lists in pure C#.

The SortedList<TKey,TValue> method solved my problem to a big extent and I could create ordered lists like:

SortedList<int, string> numberNames = new SortedList<int, string>();  numberNames.Add(1, "List item");  numberNames.Add(2, "List item");  numberNames.Add(3, "List item");  

But the bigger problem comes when you don't know exactly how many list items there will be (for example, when you're parsing errors from a user input).

Actually, I have an input output program in HTML-JavaScript which I want to replicate (It is like a small print function parser). In the program, a new list item is added to an error-panel whenever there's an error in the input, which is a string which is text, and each list item is numbered with the HTML <ol> element. An example output (in the error-panel) would be something like:

1. There is such and such error.  2. There is such and such error.  

So basically what I need is a way to create an ordered list in C# even if I don't know how many list items there will be, and if possible, with an inbuilt method...

I have searched on the internet about a ten times and have surfed a 20 sites and have not been able to find anything that satisfies this need of mine...

Please guide me through this...

https://stackoverflow.com/questions/67251776/creating-an-ordered-numbered-list-in-pure-c-sharp April 25, 2021 at 05:25PM

没有评论:

发表评论