首页 > 其他分享 >index和range的简单使用

index和range的简单使用

时间:2022-12-18 12:33:11浏览次数:34  
标签:index Console string point range WriteLine 简单 words

index和range的简单使用

1.

        static void Main(string[] args)
        {
            string[] words = new string[]
         {
                        "The",      // 0 9
                        "quick",    // 1 8
                        "brown",    // 2 7
                        "fox",      // 3 6
                        "jumped",   // 4 5
                        "over",     // 5 4
                        "the",      // 6 3
                        "lazy",     // 7 2
                        "dog"       // 8 1
         };

            // Index
            Index k = ^1;
            Console.WriteLine(words[1]);
            Console.WriteLine(words[words.Length - 1]);
            Console.WriteLine(words[^1]);
            Console.WriteLine(words[k]);

            //range 范围
            Range p = 0..3;
            string[] lists = words[p];
            foreach (var list in lists)
            {
                Console.WriteLine($"foreach:{list}");
            }

            Console.Read();
        }

2.类中使用

    class Program
    {
        static void Main(string[] args)
        {
            Point point  = new Point();
            Console.WriteLine(point[0]);
            point[0] = "gongdonghai";
            Console.WriteLine(point[0]);
            Console.Read();
        }
    }

    public class Point
    {
        public string[] gamma = new string[]
         {
                  "The",      // 0 9
                  "quick",    // 1 8
                  "brown",    // 2 7
                  "fox",      // 3 6
                  "jumped",   // 4 5
                  "over",     // 5 4
                  "the",      // 6 3
                  "lazy",     // 7 2
                  "dog"       // 8 1
         };

        //类级别索引:this
        public string this[int index]
        {
            get
            {
                return gamma[index];
            }
            set
            {
                gamma[index] = value;
            }
        }
    }

注意点

标签:index,Console,string,point,range,WriteLine,简单,words
From: https://www.cnblogs.com/ynysj/p/16990190.html

相关文章

  • Playable API - 简单播放Animation Clip
    用到的资源:GitHub-unity3d-jp/unitychan-crs:Unity-Chan"CandyRockStar"LiveDemo这边直接在他提供的Scene上修改PlayableAPI来播放AnimationClip的脚本:usin......
  • wordpress外贸独立站商城 如此简单
      2020年开始突然之间外贸独立站就火起来的,很过公司转型做B2C。外贸商城无独有偶选择wordpress,wordpress用来搭建独立站,搭建wordpress商城,都是非常不错的选择当然你也......
  • Json Net 简单的文件读取和写入
    ▲读写的文件XiaoMing.json:{"Name":"小明","Sex":"男","Age":12}JsonWriteTest.json:{"StartX":1.23,"StartY":1.24,"EndX":10,"EndY":"YY","Fa......
  • Oracle-统计信息收集-INDEX
    索引的统计信息主要包含索引blevel(索引高度-1)、叶子块的个数(leaf_blocks)以及集群因子(clustering_factor)。我们可以通过数据字典DBA_INDEXES查看索引的统计信息。创建索引......
  • C# Socket 使用简单测试示例
    引用Newtonsoft.Json.dllusingNewtonsoft.Json;进行对象序列化和反序列化。服务端:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSyst......
  • 简单认识指针数组与数组指针
    指针数组:指针数组就是一个存放指针的数组。//指针数组#include<stdio.h>intmain(){inta[5]={1,2,3,4,5};intb[]={2,3,4,5,6};intc[]=......
  • 数据库中的一些简单小问题
    1.常见SQL语句的执行顺序是怎样?(from,on,join,where,groupby,having,select,orderby,limit)2.MySQL服务端的常见组件有哪些?连接器,解析器,优化器,执行器3.MySQL中的InnoDB和MyISAM......
  • 选择排序(简单选择排序,堆排序)
    学习时间2022.12.17选择排序基本概念简单选择排序第1次,遍历整个数组,找到最小的数字,将其与第一位进行调换;第2次,遍历除以排序好的第1个数,遍历后面所有数字,找到最小的,与......
  • java数据结构与算法(day2)--简单排序
    模式:设计api实现api简单排序举例(商品排序)1.1Comparable接口介绍(排序算法更有通用性:对象排序)创建对象,并且生成豆子。创建Comparable接口1packagecn.itcast.algor......
  • maven fmpp+javacc 集成使用简单说明
    dremio以及apachecalcite使用到fmpp+javacc进行代码生成处理,以下是一个简单的集成测试fmpp的作用fmpp实际上是包装了freemarker,提供了cli以及javaapi可以方便的......