Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the indexing and scope function in Cnotify 8.0

2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you the relevant knowledge points about how to use the indexing and scope functions in Creply 8.0. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article, let's take a look at it.

A new function of index and range has been added in Category 8.0, which provides a concise syntax for accessing individual elements or ranges in a sequence.

Before providing the indexing function, we need to access an element in the sequence. We can use the subscript or some functions to get the data of the element, such as the last element in the array:

String [] arr = new string [] {"Ice Crystal Phoenix", "Master of Shadow flow", "Demacia", "Arilia", "Ice Sagittarius"}; var str1 = arr.Last () / / Ice Sagittarius var str2 = arr [arr.Length-1]; / / Ice Sagittarius introduction Index

In the process of using it, we can declare the index directly in the subscript of the array collection class, or indirectly declare the index of type Index. The usage of the index is as follows:

String [] arr = new string [] {"Ice Crystal Phoenix", / / ^ 5 "Master of Shadow flow", / / ^ 4 "Demacia", / / ^ 3 "Arilia", / / ^ 2 =. "Ice Sagittarius" / / ^ 1 = arr.Length-1}; / / ^ 0 = arr.Length / / use index ^ 1 to get the last element Console.WriteLine ($"output: {arr [^ 1]}"); / / output: ice Sagittarius Console.WriteLine ("- End-") / / create an index Index index= ^ 1 to get the last element Index index= ^ 1; Console.WriteLine ($"output: {arr [index]}"); / / output: ice shooter Console.WriteLine ("- End-"); introduction scope

Range syntax is provided in 8.0. you can get all the elements in the scope of the sequence through a simple syntax declaration, and the declaration of index in the scope is also supported to create the scope. Examples are as follows:

# # directly declare the scope in the subscript to obtain the element sequence

/ / use range [0.2] to get the elements of index 0 and 1, excluding the element string [] newarr = arr [0.2] at the end of index 2; / / the main foreach (var rin newarr) of ice crystal Phoenix and shadow stream {Console.WriteLine ($"output: {r}") } Console.WriteLine ("- End-"); string [] index_range_xarr = arr [0.. ^ 1]; / / specify the start and end ranges, starting from 0 to the penultimate foreach (var rin index_range_xarr) {Console.WriteLine ($"output: {r}") / / output: ice crystal Phoenix, master of shadow stream, Demacia, Arilia} Console.WriteLine ("- End-")

# # create a Range separately to obtain element sequence

Range range = 0.. 2; / / separately declare the range string [] newarr = arr [range]; / / the main foreach (var rin newarr) of ice crystal Phoenix and shadow stream {Console.WriteLine ($"output: {r}") / / output: ice crystal Phoenix, master of shadow stream} Console.WriteLine ("- End-")

# # do not specify the range of start and end (get all element sequences by default)

String [] index_default_arr = arr [..]; / / equivalent to arr [0.. ^ 0], get all the elements foreach (var rin index_default_arr) {Console.WriteLine ($"output: {r}") in arr; / / output: ice crystal Phoenix, master of shadow flow, Demacia, Arilia, ice shooter}

# # specify the range of start or end

String [] index_end_arr = arr [.. ^ 0]; / / equivalent to arr [0.. ^ 0], get all the elements foreach (var rin index_end_arr) {Console.WriteLine ($"output: {r}") in arr / / output: ice crystal Phoenix, master of shadow stream, Demacia, Arilia, ice shooter} Console.WriteLine ("- End-"); string [] index_left_arr = arr [^ 2.] / / equivalent to arr [^ 2.. ^ 0], get the last two elements foreach (var r in index_left_arr) {Console.WriteLine ($"output: {r}"); / / output: Ariel, ice shooter} Console.WriteLine ("- End-")

Note: if there is a mandatory declaration at the end of the range, such as [0. 2], then the sequence of elements obtained is only the elements with subscript 0 and 1, and does not contain 2 elements, that is, the "end" is not included in the range.

These are all the contents of this article entitled "how to use the indexing and scope functions in Category 8.0". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 234

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report