zoukankan      html  css  js  c++  java
  • 圈圈数字算法

    最近写一个无限来回翻页UI,  从第一页向后翻页就到达最后一页. 写了一个函数输入一个数字转换成”页区间之间的数字”

    image

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication16
    {
        class Program
        {
            static void Main(string[] args)
            {
                int len = 6;
                for (int i = -20; i < 20; i++)
                {
                    int n = ConvertCircleIndex(i, len);
                    Console.WriteLine(i + " = " + n);
                }
    
    
                Console.ReadLine();
            }
    
    
            private static int ConvertCircleIndex(int index, int circlelen) 
            {
                if (index < 0)
                {
                    index = Math.Abs(index);
    
                    if (index > circlelen)
                        index = index % circlelen;
    
                    index = (circlelen - index) % circlelen;
                }
                else
                {
                    index = Math.Abs(index);
                    index = index % circlelen;
                }
                return index; 
            }
        }
    }

    image

  • 相关阅读:
    网站数据库
    提笔不知道说啥
    预祝大家新年快乐
    又..
    明日出发
    吸气呼气
    网吧
    光阴似箭
    <转>生活中的各种食品安全问题
    老了吗?
  • 原文地址:https://www.cnblogs.com/plateFace/p/5627839.html
Copyright © 2011-2022 走看看