.net 中的 [] 括号是什么?

发布于 2024-09-03 22:12:49 字数 165 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

和影子一齐双人舞 2024-09-10 22:12:49

它们用于将属性放在类或方法(或其他东西)上。这样,您可以将数据附加到不属于实际类的类。您可以在此处了解有关它们的更多信息

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

私藏温柔 2024-09-10 22:12:49

[] 括号是 C# 中的运算符。该链接包含更详细的信息和我在下面总结的示例。

它们用于:

  • 数组类型定义
  • 访问数组的元素
  • 它们可以用作 索引器 任何类型的参数
  • 它们可用于指定 属性 <-- 这看起来像你所问的
  • 它们可用于不安全代码来索引指针的偏移量

[] brackets are an operator in C#. The link contains more detailed information and examples of what I summarized below.

They are used for:

  • Array type definition
  • Access an element of an array
  • They can be used as indexer parameters for any type
  • They can be used to specify attributes <-- This seems like what you are asking about
  • They can be used for unsafe code to index an offset from a pointer
断桥再见 2024-09-10 22:12:49

您看到 .Net 属性 (VB< /a> 或 C#),它可以注释类型和成员。

You're seeing .Net attributes (VB or C#), which can annotate types and members.

紫竹語嫣☆ 2024-09-10 22:12:49

它们是用于注释的属性方法和类。

They're attributes used to annotate methods and classes.

为你拒绝所有暧昧 2024-09-10 22:12:49

它是最常用于对某种集合进行索引的运算符。常见用途是对数组进行索引。

它们也常用于 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#.

忆依然 2024-09-10 22:12:49

它们是属性,从我的手机发布,因此我无法添加链接,只能在 msdn 中搜索属性。

They are attributes, posting from my phone so I can't add links but just search msdn for attributes.

想念有你 2024-09-10 22:12:49

正如其他人所说,它们是属性,您应该真正检查 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文