using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace QQState { class QQState { private string[] states = { "离线", "在线", "隐身", "Q我" }; private int GetState(string mystate) { int i = 0; foreach (string state in states) { if (mystate == state) return i; i++; } return -1; } public int this[string state] { get { return GetState(state); } } } class Program { static void Main(string[] args) { QQState qqstate=new QQState(); Console.WriteLine(qqstate["离线"]); Console.WriteLine(qqstate["断线"]); Console.WriteLine(qqstate["在线"]); Console.ReadKey(); } } }