分享
 
 
 

C#问答

王朝c#·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

Questions and Answers About C#

David Chappell - August 20 , 2001

[说明:文中部分内容和观点在作者的《understanding .net》一书中,有轻微变化。]

C# is one of the most visible aspects of Microsoft's .NET initiative. Developers commonly see the world through the lens of their language, and so C# can be their main aperture into .NET. Misconceptions abound, however. In this article, I'd like to address the confusions I hear most often about this new tool.

Which is better: C# or Java? The two languages have an awful lot in common, and so in some ways it's natural to try to choose a winner. The fact that each language is often viewed as the flagship of its campóC# in Microsoft's .NET environment, with Java supported by everybody elseómakes the comparison especially attractive. But it's the wrong question. Not only is there no objective answer, it wouldn't matter if there were. To see why, realize that both languages are in fact embedded in a much larger matrix of technologies. Using C# requires using the .NET Framework, including the Common Language Runtime (CLR) and the .NET Framework class library. Similarly, using Java requires using a Java virtual machine and some set of Java packages. The choice implies an enterprise vendor decision as well: C# means Microsoft (today, at least), whereas Java means IBM or BEA or some other non-Microsoft choice. Deciding which of these paths to take based solely on the language is like buying a car because you like the radio. You can do it, but you'll be happier if you choose based on the whole package.

Isn't C# just a copy of Java? In some ways, yes. The semantics of the CLR are quite Java-esque, and so any CLR-based language will have a good deal in common with Java. Creating a language that expresses those semantics in a syntax derived from C++ (for example, C#) is bound to result in something that looks a good deal like Java. Yet there are important features in C# that don't exist in Java. One good example is support for attributes, which allow a developer to easily control significant parts of her code's behavior. In .NET, attributes can be used to control which methods are exposed as SOAP-callable Web services, to set transaction requirements, and more. Still, if Microsoft had been free to make some changes to Java, my guess is that C# wouldn't exist today.

Isn't C# the native language of .NET? Every language built on the .NET Framework must use the CLR. The CLR defines core language semantics, and so all of the languages built on it tend to have a great deal in common. The biggest choice a .NET compiler writer has is the syntax his language will use. Microsoft needed to provide a natural path to the .NET Framework for both C++ and Visual Basic developers, and so the company created C# and Visual Basic.NET. Yet the facilities these two languages offer are nearly identicalóC# can do just a little bit moreóand so neither is the "native" .NET language. There is no such thing.

But won't most .NET developers eventually choose C# over Visual Basic.NET? No. Because the power of the two languages is so similar, the primary factor for developers migrating to the .NET world will probably be the syntax they prefer. Since many more developers use Visual Basic today than C++, I expect that VB.NET will be the most popular choice. For the vast majority of VB developers who are fond of VB-style syntax, there's no reason to switch to C#. I believe that the dominant language for building Windows applications five years from now will still be Visual Basic.

Will we eventually see a .NET Framework-based version of Java as a competitor to C#? Apparently not. Microsoft will never offer a complete Java environment because Sun has essentially required that Java licensees implement all of Javaósomething Microsoft will never do. (Why should it? Does anyone expect Sun to implement C#, VB.NET, and the .NET Framework?) And if a Java aficionado chooses to use a CLR-based Java compiler, such as the one included with Microsoft's JUMP for .NET technology, she's unlikely to be truly happy. Java implies a series of Java libraries and interfaces, such as Swing and Enterprise JavaBeans. The .NET Framework provides its own equivalent technologies, and so most of these won't be available. As a result, a developer using the Java language on the .NET Framework won't feel like she's working in a true Java environment because the familiar libraries won't be there.

C# is probably the most important new programming language since the advent of Java, and it will be used by many developers. But it may have gotten more attention than it deserves, if only because focusing on this new language tends to obscure the many other important innovations in the .NET Framework. Take it seriously, but don't think it's the main event in the new world of .NET.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有