| |

VerySource

 Forgot password?
 Register
Search
View: 1495|Reply: 12

In C #, how to automatically generate an increasing number of natural numbers, and only add and not decrease?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-3 14:00:02
| Show all posts |Read mode
I want the program to automatically generate a sequence of natural numbers such as 1, 2, 3, 4 ..... and require that the number be incremented once when it is called once, and that the number is only increased. Does C # have such a function?
Reply

Use magic Report

0

Threads

119

Posts

67.00

Credits

Newbie

Rank: 1

Credits
67.00

 China

Post time: 2020-5-15 02:30:01
| Show all posts
Write it yourself!
Reply

Use magic Report

0

Threads

13

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-5-15 21:45:01
| Show all posts
I have n’t encountered such a function, and I have never considered such a problem as the landlord.
Reply

Use magic Report

0

Threads

9

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-5-20 12:15:01
| Show all posts
public sealed class Sequence {
    private static int num = 0;
    public static int Next () {
       return ++ num;
    }
}
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-5-21 09:45:02
| Show all posts
sequence.next ()
Reply

Use magic Report

0

Threads

110

Posts

63.00

Credits

Newbie

Rank: 1

Credits
63.00

 China

Post time: 2020-5-21 21:45:02
| Show all posts
TO:cqgangMM

Knowing that there is Sequence in Oracle, you can also use Sequence.Next () in C #.
Reply

Use magic Report

0

Threads

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-22 22:45:01
| Show all posts
++
Reply

Use magic Report

0

Threads

38

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-5-24 11:30:01
| Show all posts
Sorry, I mean calling my custom method upstairs ~
Reply

Use magic Report

1

Threads

31

Posts

22.00

Credits

Newbie

Rank: 1

Credits
22.00

 China

Post time: 2020-5-25 11:45:01
| Show all posts
yonger
Method is good,
However, it is best to add a reset method, which can be cleared.
:)
Reply

Use magic Report

0

Threads

11

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-5-26 15:45:01
| Show all posts
Everyone is done, I leave a mark
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list