标签:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _18._7章小结及任务实施 { class QQState { string[] qqState = {"在线","离线","Q我","隐身","忙碌" }; private int getState(string stringState) { int i = 0; foreach(string State in qqState) { if (State == stringState) return i; i++; } return -1; } public int this[string state] { get { return getState(state); } } } class Program { static void Main(string[] args) { QQState qs = new QQState(); Console.WriteLine("在线:{0}",qs["在线"]); Console.WriteLine("离线:{0}", qs["离线"]); Console.WriteLine("断线:{0}", qs["断线"]); Console.Read(); } } }
标签:
原文地址:http://www.cnblogs.com/zqyo2000z/p/5667289.html