Giter Club home page Giter Club logo

sdcb.system.range's Introduction

Sdcb.System.Range NuGet

Provide System.Index, System.Range for C# 8.0.

This file is almostly copied from following url:

Index example:

var last = ^1;
int[] arr = { 1, 2, 3 };
int lastItem = arr[last];
Console.WriteLine(lastItem); // 3

int lastItem2 = arr[arr.Length - 1];
Console.WriteLine(lastItem2); // 3

Range example:

// Old school: 
string text1 = "the quick brown fox jumped over the lazy dogs";
string lazyDogs1 = text1.Substring(36, 9);
string lazyDogs2 = text1.Substring(text1.Length - 9, 9);

// Range style: 
string lazyDogs3 = text1[^9..^0];  // lazy dogs

// lazyDogs4 is exactly the same as lazyDogs3
var start = ^9;
var end = ^0;
var range = Range.Create(start, end);
string lazyDogs4 = text1.Substring(range);

// Other usages:
string lazyDogs5 = text1[^9..];  // Range.FromStart
string lazyDogs6 = text1[36..]; // Range.FromStart
string thequick = text1[..9]; // Range.ToEnd
string completeString = text1[..]; // Range.All

// Ranges with array: 
var arr = new[] { 1, 4, 8, 11, 19, 31 };
var range = arr[2..5];
ref int elt = ref range[1];
elt = 42;
int copiedelement = range[1];
copiedelement = 11;
Console.WriteLine($"the original element is changed: {arr[3]}"); // 42

Note: this code requires roslyn version 2.9.0 or later to run:

sdcb.system.range's People

Contributors

sdcb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.