Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3662400
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:24:44+00:00 2026-05-19T01:24:44+00:00

I`m trying to create a special counter in C# … I mean the counter

  • 0

I`m trying to create a special counter in C# … I mean the counter will be consisting of characters not numbers.

I have a char[] of size 3:

char[] str = new char[strSize];
int i = 0;
int tmpSize = strSize - 1;
int curr;
while(!isEqual(str,finalStr,strSize))
{
    str[strSize] = element[i % element.Length];
    i++;
    if (str[strSize] == element[element.Length - 1])
    {
        int j = strSize - 1;
        if (j > 0)
        {
            j--;
            int tmpCntr = j+1;
            curr = getCurrentID(str[tmpCntr]);
            str[tmpCntr] = element[(curr + 1) % element.Length];
            while (str[tmpCntr] == element[0] && (i % element.Length > 0) && tmpCntr < 0)
            {
                tmpCntr--;
                curr = getCurrentID(str[tmpCntr]);
                str[tmpCntr] = element[(curr + 1) % element.Length];
            }
        }
    }
}

if the strSize < 3 the application works fine and gives accurate output. If the strSize >= 3, the application goes in infinite loop!

Need help.

if this is hard this way, I would need a way to create a numerical counter and I`ll work on it to suite my application.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:24:45+00:00Added an answer on May 19, 2026 at 1:24 am

    You haven’t shown what half of your methods or parameters are.

    Personally I would take a different approach. I would use an iterator block to make it easy to return an IEnumerable<string>, and internally just keep an integer counter. Then you just need to write a method to convert a counter value and “alphabet of digits” into a string. Something like this:

    public static IEnumerable<string> Counter(string digits, int digitCount)
    {
        long max = (long) Math.Pow(digits.Length, digitCount);
        for (long i = 0; i < max; i++)
        {
            yield return ConvertToString(i, digits, digitCount);
        }
    }
    

    Another alternative is to do the same thing with LINQ, if a range of int is enough:

    public static IEnumerable<string> Counter(string digits, int digitCount)
    {
        int max = (int) Math.Pow(digits.Length, digitCount);
        return Enumerable.Range(0, max)
                         .Select(i => ConvertToString(i, digits, digitCount));
    }
    

    In either case, you just iterate over the returned sequence to get appropriate counter values.

    With those in place, you just need to implement ConvertToString – which would probably be something like this:

    public static string ConvertToString(long value, string digits, int digitCount)
    {
        char[] chars = new char[digitCount];
        for (int i = digitCount - 1 ; i >= 0; i--)
        {
            chars[i] = digits[(int)(value % digits.Length)];
            value = value / digits.Length;
        }
        return new string(chars);
    }
    

    Here’s a test program showing it all working:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    class Test
    {
        static void Main()
        {
            // Show the first 10 values
            foreach (string value in Counter("ABCD", 3).Take(10))
            {
                Console.WriteLine(value);
            }
        }
    
        public static IEnumerable<string> Counter(string digits, int digitCount)
        {
            long max = (long) Math.Pow(digits.Length, digitCount);
            for (long i = 0; i < max; i++)
            {
                yield return ConvertToString(i, digits, digitCount);
            }
        }
    
        public static string ConvertToString(long value,
                                             string digits,
                                             int digitCount)
        {
            char[] chars = new char[digitCount];
            for (int i = digitCount - 1 ; i >= 0; i--)
            {
                chars[i] = digits[(int)(value % digits.Length)];
                value = value / digits.Length;
            }
            return new string(chars);
        }
    }
    

    Output:

    AAA
    AAB
    AAC
    AAD
    ABA
    ABB
    ABC
    ABD
    ACA
    ACB
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to place a UIImageView in a UITableViewCell. I create a special view
I am trying to create a special style sheet for mobile devices (for example
I'm trying to create a jQuery special event that triggers when the content that
I'm trying to create a child class of TForm with a special constructor for
I have about 100 elements in like and am trying to create an animation
I'm trying to create a special button that colors an image based on Foreground
I'm trying to create a plugin for Android Mail App. this plugin will filters
I am trying to create control which will take ItemsSource and InnerTemplate and will
I am trying to create a regular exp to to stop user entering special
I am trying to create a basic internal messaging system. The only 'special' consideration

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.