静态数组的定义
我一直在寻找静态数组的合适定义。我尝试过使用 msdn 和 c# 源代码,但似乎找不到定义。它给出了示例,但没有定义...
有人知道静态数组的任何链接或定义和特征吗?
I've been looking for a decent definition of static arrays. I've tried using msdn and c# sources but cannot seem to find a definition. It gives examples, but no definitions...
Does anyone know any links or definitions and characteristics of a static array please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您谈论“静态数组”时,您实际上是在谈论两个不同的事物。
其中之一是
static
关键字。当应用于变量时,这意味着该变量位于类级别,并且该类型的每个对象都不会获得自己的实例。数组只是一种用于保存某种类型的多个值的数据结构。
因此,静态数组只是类级别的数组,可以保存多种数据类型。
例如:
在您的
TravelRoute
类中,您的路线中可能有一定数量的可能目的地。这些可以这样定义:这将定义
TravelRoute
上可能的目的地。然后您可以像这样访问该数组:When you talk about a 'static array' you are really talking about two separate things.
One would be the
static
keyword. When applied to variables this means that the variable lives at theclass
level, and each object of that type will not get its own instance.An
array
is simply a data structure for holding multiple values of some type.So, a
static array
is simply an array at the class level that can hold multiple of some data type.For example:
In your
TravelRoute
class, you may have a set number of possible destinations in a route. These could be defined like so:This will define the possible destinations on a
TravelRoute
. You can then access the array like so:您可能指的是固定大小的数组吗?
如果是这样,通过使用固定大小的数组作为查询,您将获得更多搜索结果:)
Do you possibly mean fixed size arrays?
If so, you will get more search results by using fixed size arrays as your query :)
(据我所知)静态数组本身没有什么特别的,这可能就是为什么你很难找到关于它们的好的文章。如果我错了,请纠正我,但我想知道您最感兴趣的是“静态”部分吗?基本上,静态意味着成员存在于类级别而不是实例级别,因此静态数组将是属于该类(而不是该类的实例)的数组。
例子:
There's nothing (that I know of) that's special about static arrays, per se, which may be why you're having trouble finding good write-ups about them. Correct me if I'm wrong, but I wonder if it's the "static" part that you're most interested in? Basically, static means that the member exists at the class level rather than the instance level, so a static array would be an array that belongs to the class (rather than an instance of the class).
Example: