大虾帮忙灌水:在定义类时,插入"[...]"是什么意思?

zhhzxl 2002-11-04 02:19:50
我经常看到如下的表述:
例一:
...
[ConstructionEnabled( Default = "Data Source=localhost; Initial Catalog=NorthWind; User id=sa; Password=;" )]
public class A:B
{...}
...

例二:
...
[STAThread]
static void Main(string[] args)
{...}
...

这些“[...]”到底是表达什么意思?
帮忙灌水,谢谢谢谢!!!
...全文
48 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
AhBian 2002-11-06
  • 打赏
  • 举报
回复
TheAres(班门斧),你好。

你要看清楚了,他指的是 “[...]”不是“{...}”。

.net 比 Java 高一点的地方,说的很对。

特性提供了元数据功能。
fourfire29 2002-11-06
  • 打赏
  • 举报
回复
类、方法的属性,就不能放在配置文件中吗?
seakingii 2002-11-06
  • 打赏
  • 举报
回复
这种基础的东西还要讨论吗?会不会是浪费时间呢?
sunny6281 2002-11-05
  • 打赏
  • 举报
回复
TheAres(班门斧) :
你很幽默:)
chenbinghui(阿炳) 说的是正解:)
第二个问题:
定义数组
比如:string[] 表示string 数组
int[]表示整形数组:)
steeven 2002-11-04
  • 打赏
  • 举报
回复
.net比java高一点的地方
TheAres 2002-11-04
  • 打赏
  • 举报
回复
很简单,
...就是省略号.

例二:
...
[STAThread]
static void Main(string[] args)
{...}
...
这个地方表示是程序的片断.
[STAThread]上面还有其他的.
{...}是Main中的具体实现省略了.

AhBian 2002-11-04
  • 打赏
  • 举报
回复
这个问题很简单,但不知道的人看起来很复杂,这就是 .Net 引入的 “特性” 概念。相关书籍解释的很多也很清楚,我只能指点你去看 C# 的入门书籍,不然也太浪费时间了,估计版面也不太够。

只要去看有关“特性”(Attribute)的资料,这个问题非常容易搞得懂,真的一点也不难,看懂了你会知道用处实在多多。
chenbinghui 2002-11-04
  • 打赏
  • 举报
回复
定义类的一些Attribute,这些Attribute不是类成员,而属于类的Type,在Type.GetType("MyClass").Attributes可以找到这些这些属性,[ConstructionEnabled( Default = "Data Source=localhost; Initial Catalog=NorthWind; User id=sa; Password=;" )]说明的是
有一个class ConstructionEnabled(或者ConstructionEnabledAttribute),他含有property Default,"Data Source=localhost; Initial Catalog=NorthWind; User id=sa; Password=;"是给Default置值,
想上面那样定义之后,你就可以这样来访问:
ConstrutionEnable ce=(ConstrutionEnable)Type.GetType("A").Attributes[0];
Console.WriteLine(ce.Default);
文笔不好,说不清楚.大概就是这样
henryfan1 2002-11-04
  • 打赏
  • 举报
回复
好像是定义其属性吧

111,117

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧