• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 459
  • Last Modified:

asp.net for loop alphabets

I have nested for loop in asp.net C# page

I want each item in the first for loop to be A ,B,C,D,E...
and the items in inside loop to be 1.1,1.2,1.3... in A
2.1,2.2,2.3.. in B

A.test
1.1
1.2
1.3
B mytest
2.1
2.2
2.3
C gtest
3.1.
3.2
3.3
3.4
.
.
.
.
and so on
Any help appreciated
0
Angela4eva
Asked:
Angela4eva
1 Solution
 
kris_perCommented:

Something like this? Hope it gives you the idea to suit yours...


            for (char alpha = 'A'; alpha <= 'Z'; alpha++)
            {
                Console.WriteLine(alpha);

                int sectionNum = alpha - 'A' + 1;

                // the criteria for the second part of num is not mentioned in your question
                // it is taken as 4 for all sections
                for (int subSectionNum = 1; subSectionNum <= 4; subSectionNum++)
                {
                    Console.WriteLine(sectionNum + "." + subSectionNum);
                }
            }

            // Output of this will be:
            A
            1.1
            1.2
            1.3
            1.4
            B
            2.1
            2.2
            2.3
            2.4
            ...
            till Z

Open in new window

0
 
Angela4evaAuthor Commented:
great. thanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now