在c#win中获取下一个序列号。形成 [英] Getting the next series number in c# win. form

查看:60
本文介绍了在c#win中获取下一个序列号。形成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在获取下一个系列号。示例: -



1)我从1开始系列,在获得下一个系列号2时,我将这样的记录保存到100



2)然后我跳过这些数字直到149并开始系列从150到200



3)之后当我再次将系列从101改为149 时, 149后的下一个系列号应该到201 的。如何解决这个问题?

解决方案

具体如何做到这将取决于你的代码 - 我们不知道它是如何工作的。

但是 - 假设你有一组值,它并不复杂:

 List< int> existing =  new  List< int>(); 
for int i = 1 ; i < = 100 ; i ++)existing.Add(i);
for int i = 150 ; i < = 200 ; i ++)existing.Add(i);
int minUnused = Enumerable.Range(existing.Min(),existing.Max()+ 1 )。除了(现有).Min();


不确定你想要什么,但......



看看例子:

 使用系统; 
使用 System.Collections.Generic;
使用 System.Text;

命名空间 ConsoleApplication1
{
class 计划
{
静态 void Main( string [] args)
{
List< int> Serials = new List< int>();
int tmpv = 0 ;
for int i = 96 ; i < = 202 ; i + = 2
{
tmpv = GetNextSN(i);
if (tmpv> 0&&!Serials.Contains(i))
{
Serials.Add(tmpv) ;
}
Console.WriteLine( 当前值:{0}; SN:{1} ,I,TMPV);
}
Console.ReadKey();
}

静态 int GetNextSN( int currSN)
{
int rv = currSN;
if (rv < = 100
return rv;
else
{
while (rv > 100
{
rv - = 100 ;
}
如果(rv> = 1 && rv< = 49
rv = currSN;
else
rv = 0 ;
return rv;
}
}
}
}





根据需要更改代码。


I am stuck in getting the next series number. Example :-

1) I started the series from 1 and on getting the next series number 2, i saved the records like this till 100.

2) Then I skipped the numbers till 149 and started the series from 150 to 200.

3) After that when i again change the series from 101 till 149, the next series number after 149 should come 201. How to solve this?

解决方案

Exactly how you do this will depend on your code - and we have no idea how that works.
But - assuming that you have a collection of values, it's not complex:

List<int> existing = new List<int>();
for (int i = 1; i <= 100; i++) existing.Add(i);
for (int i = 150; i <= 200; i++) existing.Add(i);
int minUnused = Enumerable.Range(existing.Min(), existing.Max() + 1).Except(existing).Min();


Not sure what you want, but...

Have a look at example:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> Serials= new List<int>();
            int tmpv =0;
            for (int i = 96; i <= 202; i += 2)
            {
                tmpv = GetNextSN(i);
                if(tmpv>0 && !Serials.Contains(i))
                {
                    Serials.Add(tmpv);
                }
                Console.WriteLine("Current value: {0}; SN: {1}",i,tmpv);
            }
            Console.ReadKey();
        }

        static int GetNextSN(int currSN)
        {
            int rv = currSN;
            if (rv <= 100)
                return rv;
            else
            {
                while (rv > 100)
                {
                    rv -= 100;
                }
                if (rv>=1 && rv<=49)
                    rv = currSN;
                else
                    rv = 0 ;
                return rv;
            }
        }
    }
}



Change the code to your needs.


这篇关于在c#win中获取下一个序列号。形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆