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 C# index

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

Share

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

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!

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: 0

*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