Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the C# index

Shulou Source: shulou.com Published: 2022-06-02 08:38:21 10月20日 Update

Editor to share with you how to use the C# index, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Here is the posted code:

Using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace index {class Worker {public string LastName; public string FirstName; public string MyBirth Public string this [int index] {set {switch (index) {case 0: LastName = value Break; case 1: FirstName = value; break; case 2: MyBirth = value Break; default: throw new ArgumentOutOfRangeException ("index"); break }} get {switch (index) {case 0: return LastName Case 1: return FirstName; case 2: return MyBirth; default: throw new ArgumentOutOfRangeException ("index") Break }} class Program {static void Main (string [] args) { Worker a = new Worker () Console.WriteLine ("print the value: {0}, {1}, {2}", a [0], a [1], a [2]); Console.WriteLine ("please print your last name"); a [0] = Console.ReadLine (); Console.WriteLine ("please print your first name") A [1] = Console.ReadLine (); Console.WriteLine ("please print your birthday"); a [2] = Console.ReadLine (); Console.WriteLine ("Now,your name is {0}, {1}, and your birth is {2}", a [0], a [1], a [2]) }}}

First of all, what is a C# index?

It is said in the book that it is a set of get and set accessors, which I personally think directly is the concept of getting or setting values. It may be wrong, hehe, the theory is too bad, I just read it.

How to declare a C# index?

His grammar is as follows:

Note the following: a: the index does not have a name, it is through the keyword this.

B: the parameter list is in square brackets.

C: the parameter list must declare at least one parameter.

ReturnType this [type param1,...] {get {...} set {...}} these are all the contents of the article "how to use the C # Index" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Indexing clocking parameters articles content not so much individuals codes keywords names most of them square brackets more concepts theory knowledge industry grammar Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Xiaomi Redmi Linux