tags:

views:

281

answers:

2

Hi All,

total string length is 5 chars

I have a scenario, ID starts with

A0001 and ends with A9999 then B0001 to B9999 until F0001 to f9999

after that

FA001 to FA999 then FB001 to FB999 until ....FFFF9

Please suggest any idea on how to create this format

Thanks in advance

+3  A: 
public static IEnumerable<string> Numbers()
{
    return Enumerable.Range(0xA0000, 0xFFFF9 - 0xA0000 + 1)
        .Select(x => x.ToString("X"));
}

You could also have an id generator class:

public class IdGenerator
{
    private const int Min = 0xA0000;
    private const int Max = 0xFFFF9;
    private int _value = Min - 1;

    public string NextId()
    {
        if (_value < Max)
        {
            _value++;
        }
        else
        {
            _value = Min;
        }
        return _value.ToString("X");
    }
}
Darin Dimitrov
first thanks for the quick reply, like I need to store the information in DB ...each time I will get the latest ID from DB based on that latest ID I need to generate new Uniqu ID.
I don't understand what you are asking. In your original question you clearly described the algorithm needed for generating unique ID numbers. Restate your question and explain what is the algorithm used to generate an ID given some other ID.
Darin Dimitrov
A: 

hello, Dear Darvin Dimitrov

Its very Useful code to me...but how can i use it. means where i have to put this code and where it will show there unique id please give a proper format.

i just need to auto generate id like abc101,abc102,abc103,....abc10n and it should be store in DB table. and also it should be show in any textbox at runtime .

Please give a proper solution....

Special Thanks in advance :)

Regards.

Pradeep Kodley

pradeepKodley