Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# negative index

var words = new string[]
{
                // index from start    index from end
    "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
};              // 9 (or words.Length) ^0
Comment

negative indexing in c#

// negative indexing is supported only in C# 8.0 and above
var favoriteShows = new string[] { "Firefly", "Cowboy Bebop", "Samurai Champloo" };

            Console.WriteLine(favoriteShows[^1]); // "Samurai Champloo"
            Console.WriteLine(favoriteShows[^2]); // "Cowboy Bebop"

            Index idx = ^3; // You can declare an index as a variable
            Console.WriteLine(favoriteShows[idx]); // "Firefly"
Comment

PREVIOUS NEXT
Code Example
Csharp :: mysql executeScalar only if successful 
Csharp :: overloading constructors c# 
Csharp :: F# tuple get item 
Csharp :: c# generate random date of birth but over 18 
Csharp :: replace filename extension c# 
Csharp :: process method in scala 
Csharp :: how to show messagebox 
Csharp :: how to change something in the window using a thread wpf 
Csharp :: nodatime instant to datetime off set c# 
Csharp :: c# convert address to int 
Csharp :: How do I remove a String Array from a List in C# 
Csharp :: c# loop datatable column names convert to list 
Csharp :: ${1##*[! ]} 
Csharp :: opération inter-threads non valide 
Csharp :: unknown discriminator value mongodb 
Csharp :: how to make a console feedback 
Csharp :: how to find any component of gameobject itself in untiy 
Csharp :: list.SkipWhile in c# 
Csharp :: scroll two divs simultaneously site:stackoverflow.com 
Csharp :: how to preset an array c# 
Csharp :: dictionary and generic class c# 
Csharp :: C# Bitwise Left Shift 
Csharp :: isselected uicollectionview reused 
Csharp :: c# blazor update state 
Csharp :: index was out of the bound array in c# 
Csharp :: .net mvc foreach with index 
Csharp :: linq contains null 
Csharp :: How to do a comment in c# 
Csharp :: beard styles without mustache Intitle:work with me 
Csharp :: what is vector3.one c# 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =