仓酷云

标题: ASP.NET教程之C#进修条记之四(Attribute, Reflectio... [打印本页]

作者: 简单生活    时间: 2015-1-16 22:50
标题: ASP.NET教程之C#进修条记之四(Attribute, Reflectio...
我以前很喜欢Serv-U,自从它用Java重写之后我就再也没用过,实在是太慢了,我宁可用IIS搭建FTP,虽然IIS搭建FTP在权限管理上很不灵活。Atributes:
//canaddmetadatainprogram,Itstorewiththeprogram
//usingILDasmtocheckatributes

//usage
[CodeReviewAttribute("08/08/2005","AllanZhang",
Comment="ThatisaAttributetest")]
classEmployee{}

//definetargetandatr
[AttributeUsage(AttributeTargets.Class|
AttributeTargets.Constructor|
AttributeTargets.Interface|
AttributeTargets.Method|
AttributeTargets.Field|
AttributeTargets.Property,
AllowMultiple=true)]
classCodeReviewAtrribute:System.Attribute
{
privatestringreviewDate;
privatestringreviewerName;
privatestringreviewComments;
...
}

Reflections://lookthemetadatainprogram,discory,latebinding

//DisplayattributeinCode
System.Reflection.MemberInfoinf=typeof(Employee);
object[]atributes=inf.GetCustomAttributes(false);
foreach(objectattributeinattributes)
{
CodeReviewAttributeattr=(CodeReviewAttribute)attribute;
Console.WriteLine("Thisiscodewasreviewedon{0}by{1}
Comments{2}",
attr.date,
attr.name,
attr.comment)
}

//Discovery
Assemblyasm=Assembly.Load("Mscorlib.dll");
Type[]types=asm.GetTypes();
foreach(Typetypeintypes)
{
Console.WriteLine("Typeis{0},type);
Console.WriteLine("
{0}typesfound."types.Length);
}

//LateBinding
TypemathType=Type.GetType("System.Math");
objectobj=Activator.CreaterInstance(mathType);

Type[]parameterTypes=newType[2];
parameterTypes[0]=Type.GetType("System.Double");
parameterTypes[1]=Type.GetType("System.Double");
MethodInfopowInfo=mathType.GetMethod("Pow",parameterTypes);

object[]parameters=newobject[2];
parameters[0]=5;
parameters[1]=3;
objectreturnValue=powInfo.Invoke(obj,parameters);
Console.WriteLine("5tothe3rdpoweris{0},returnValue);

Thread:
//CreateImplicitThreads

usingSystem.Threading
ThreadthreadOne=newThread(newThreadStart(Countup));
ThreadthreadTwo=newThread(newThreadStart(Countup));
threadOne.Name="ThreadOne";
threadTwo.Name="Threadtwo";
threadOne.Start();
threadTwo.Start();

//Joining&killingThreads
//jointwothreadsincurrentthrea
threadOne.start();
threadTwo.Start();
threadOne.Join();
threadTwo.Join();
//thiswillprint,aftertwoabovetwothreadsends
Console.WriteLine("Theotherthreadsdone");
//sleep(millisenconds)
threadOne.sleep(1);
threadOne.Abort();

Synchronization:
//1.noconflictbetweenthreads
interlocked.Increment(refsynchValue);
//2.lockmethod,thiswillblockotherthreadwhenitenterintoit
lock(this)
{
inttemp=synchValue;
temp++;
Thread.Sleep(2);
synchValue=temp;
synchValue=temp;
Console.WriteLine("{0}Countup:{1}",
Thread.CurrentThread.Name,
synchValue);
}

Java欺骗了我们那么多年,如今的多核时代,我认为它气数已尽!
作者: 山那边是海    时间: 2015-1-18 16:28
使用普通的文本编辑器编写,如记事本就可以完成。由脚本在服务器上而不是客户端运行,ASP所使用的脚本语言都在服务端上运行,用户端的浏览器不需要提供任何别的支持,这样大提高了用户与服务器之间的交互的速度。
作者: 不帅    时间: 2015-1-22 12:37
ASP在执行的时候,是由IIS调用程序引擎,解释执行嵌在HTML中的ASP代码,最终将结果和原来的HTML一同送往客户端。
作者: 谁可相欹    时间: 2015-1-31 06:41
由于JSP/Servlet都是基于Java的,所以它们也有Java语言的最大优点——平台无关性,也就是所谓的“一次编写,随处运行(WORA–WriteOnce,RunAnywhere)”。除了这个优点,JSP/Servlet的效率以及安全性也是相当惊人的。
作者: 海妖    时间: 2015-2-6 17:55
能产生和执行动态、交互式、高效率的站占服务器的应用程序。运用ASP可将VBscript、javascript等脚本语言嵌入到HTML中,便可快速完成网站的应用程序,无需编译,可在服务器端直接执行。容易编写。
作者: 变相怪杰    时间: 2015-2-17 22:08
逐步缩小出错代码段的范围,最终确定错误代码的位置。
作者: 灵魂腐蚀    时间: 2015-3-5 23:12
ASP在执行的时候,是由IIS调用程序引擎,解释执行嵌在HTML中的ASP代码,最终将结果和原来的HTML一同送往客户端。
作者: 兰色精灵    时间: 2015-3-12 16:35
现在的ASP.net分为两个版本:1.1和2.0Asp.net1.1用VS2003(visualstudio2003)编程。Asp.net2.0用VS2005(visualstudio2005)编程。现在一般开发用的是VS2003。
作者: 因胸联盟    时间: 2015-3-20 00:11
现在主流的网站开发语言无外乎asp、php、asp.net、jsp等。




欢迎光临 仓酷云 (http://ckuyun.com/) Powered by Discuz! X3.2