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 :: c# datetimepicker set weeks before today 
Csharp :: unity lock cursor to center 
Csharp :: best practice c# check if string is null or whitespace 
Csharp :: c# get all class properties 
Csharp :: c# stringbuilder to file 
Csharp :: c# xpath read attribute value 
Csharp :: how to get the path of the current directory in c# 
Csharp :: create models from database ef core 
Csharp :: c# console beep sounds 
Csharp :: c# create file 
Csharp :: beep sound in c# 
Csharp :: csharp check if env is development 
Csharp :: How can you learn C# on your own 
Csharp :: c# linq to dictionary 
Csharp :: small modal popup bootstrap 
Csharp :: unity instantiate with name 
Csharp :: wpf get screen size 
Csharp :: frame time unity 
Csharp :: import time C# 
Csharp :: how to convert nullable datetime datarow to datetime in c# 
Csharp :: how to deactivate objects through scripts in unity 
Csharp :: trigger collider unity 
Csharp :: how to loop over array in c# 
Csharp :: if statement swiftui 
Csharp :: .net Core Get File Request 
Csharp :: csharp 
Csharp :: javascript close page after 5 seconds 
Csharp :: Cursor Lock and Visible in Unity 
Csharp :: if button is pressed unity 
Csharp :: access to element in object c# 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =