【发布时间】:2016-08-25 09:24:51
【问题描述】:
目前我的代码是这样的
public class ExampleClass
{
private static string[] words = new string[] { "Word1","Word2","Word3","Word4","Word5" };
public static bool IsExist(string Word)
{
return words.Any(w => w == Word);
}
}
我称之为
ExampleClass.IsExist("Word1"); //Returns true
ExampleClass.IsExist("WordNotExist"); //Returns false
但我想这样打电话
ExampleClass.IsExist["Word1"]; //Returns true
ExampleClass.IsExist["WordNotExist"]; //Returns false
我应该如何修改我的课程,请帮帮我
【问题讨论】:
-
你为什么要那个?它不是一个数组,对吧?
-
我看不出有什么原因,你不能在静态类中声明索引属性。
-
没问题,我的代码完全不同。请给我任何想法我必须做些什么来完成这个
标签: c#