.net 中的 [] 括号是什么?
我在 C# 中很少见过 [] 这样的括号,但是当我开始学习 ASP.NET 时,我已经见过它们很多次了,但我仍然无法理解它们的作用?
它们不是用于数组的代码的一部分。例如 [webmethods] 就在方法之上,或者有一些在类之上。它们是 .net 的一部分还是只是向 CLR 传达一些信息?或者 ?
i have seen [] such brackets in c# very very rarely but when i start to learn asp.net i have seen them many times but still i couldn't understand what they does ?
They are not part of code as using for arrays.For example [webmethods] which is just over the methods or there are some over classes. Are they part of .net or they are just tell something to CLR ? or ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
它们用于将属性放在类或方法(或其他东西)上。这样,您可以将数据附加到不属于实际类的类。您可以在此处了解有关它们的更多信息
They are used to put Attributes on classes or methods (or other stuff). That way, you can attach data to classes that should not be part of the actual class. You can read more on them here
[] 括号是 C# 中的运算符。该链接包含更详细的信息和我在下面总结的示例。
它们用于:
[] brackets are an operator in C#. The link contains more detailed information and examples of what I summarized below.
They are used for:
您看到 .Net 属性 (VB< /a> 或 C#),它可以注释类型和成员。
You're seeing .Net attributes (VB or C#), which can annotate types and members.
它们是用于注释的属性方法和类。
They're attributes used to annotate methods and classes.
它是最常用于对某种集合进行索引的运算符。常见用途是对数组进行索引。
它们也常用于 C# 中定义属性。这些可以出现在方法和类上面。它们是为该类或方法定义额外行为的一种方式。
MSDN 有一篇很好的 C# 属性简介。
It is an operator which is most commonly used for indexing into some sort of collection. The common use is for indexing into an array.
They are also commonly used in C# to define attributes. These can appear above methods and classes. They are a way of defining extra behavior for that class or method.
MSDN has a good Introduction to Attributes in C#.
它们是属性,从我的手机发布,因此我无法添加链接,只能在 msdn 中搜索属性。
They are attributes, posting from my phone so I can't add links but just search msdn for attributes.
正如其他人所说,它们是属性,您应该真正检查 MSDN关于它们,但简而言之,你可以说它们添加了可以在方法执行之前或之后执行的代码,或者根本不执行!它们做很多不同的事情,从作为条件来决定方法是否应该运行,进行预处理操作,到只是将元数据添加到代码中,以便其他库或编译器可以找到它并用它做一些事情。
As some other said, they are attributes, you should really check MSDN about them, but in short, you could say they add code that can can be executed before or after the method is executed, or not at all! They do many different things, from being conditionals to decide if the method should run or not, to do a preprocessing operation, to just adding MetaData to the code, so other libraries or the compiler can find it and do stuff with it.