After a few days, I finally found a little free time to continue us to experience the process. Today we have to experience Visual C # 2005 Express Edition Beta. It can be said that open the VC # interface, not given me what surprises, but the fresh and bright startup page still attracts my gaze. As shown in the figure, there is some link to the experience in the startup page, with a "Create A Screen Saver With the C # Starter Kit" I am afraid I can attract a lot of rookie players like me, we will It starts! Follow the prompts, we create a Screen Saver project through File> New> Project, familiar with Visual Studio .NET 2003, friends may be very shocked, and there is no need to specify the saved path when the new project is found. Yes, in VC # 2005, a model similar to Delphi, VB6 is taken, which only allows you to specify the path when you ask for a project, so that people who like to write a small test program are It is very convenient, don't worry about leaving more and more small garbage items on the hard drive. Ok, you can try it, VC # 2005 has created a screen saver that can be run, this program also has RSS news reading features! The default RSS address is stored in app.config, you can change it to your own blog address :) From the default generated project, we can see that the wizard coded compared to the VS2003 Putting Static void main () from the form class out of a class named Program, this structure can be said to be clearer for friends who just came to. In addition, we can also see some new features of C # 2.0 from the code generated by the wizard. Now the article introduces C # 2.0's article is quite much, I don't have a comprehensive introduction to it here, how much is it? First look at the files of the generated form, in VS2003, usually a form has two files composed .cs is code, .resX is the resource, in VC # 2005, by using C # 2.0's Partial Class feature, The original .CS code file is split into two .cs files, a implementation of the form interface constructor, a implementation of other code. The so-called Partial Class features, in fact, putting a class's code can be split into two .cs files, in order to achieve this feature, you only need to add Partial keyword before you want to fold the partial class. . This small improvement is actually a lot of benefits, such as: use it to implement Code Behind technology similar to the ASP.NET when designing the form program. When multi-developers are developing a class, it can also reflect advantages in Source Control: Each developer can develop separate synchronizations without having to conflict with people in different parts of the Check Out class. What if there is a conflict contradiction between a different part of a class? A class of elements can have two kinds of accumulation and non-accumulation, so-called accumulation, it is possible to combine multiple parts, such as implementing interface, attributes, fields, etc., non-accumulated is not Combined elements, such as visibility, base classes, etc., each part of the requirement is required to be uniformly defined for these non-accumulated elements. When a different portion of a class makes different definitions, the compiler will report an error. C # 2.0 Another important feature is an anonymous method. Many times, we have to create a way in order to use a delegate.
For example, we draw a button on the form. If you double click, it generates its event response method. Vs actually made a lot of things, first it entrust it to Button.Click event: this.button1.click = new system.eventhandler (this.button1_click); then generates the corresponding method: Private void button1_click (Object sender, eventargs e) {messagebox.show ("test");} Of course this is just an example, just like you look now In the case, this method may only have a few lines of code, but the entrusted is often used for callback, asynchronous call, multi-thread, etc., such a Dongcou will look very drag. Therefore, through an anonymous methods, we can combine the above two codes, write: this.button1.click = new system.eventhandler (delegate (Object Sender, EventArgs E) {MessageBox.show ("Test");} ); New features of C # 2.0 first say so much, VC # 2005 main menu strip on a word --Refactor - maybe very attractive attention, VC # 2005 first introduces code reconstructed in the VS family Just as you can see, it implements several reconstructed modes such as extract method, rename, encapsulate field. I remember at the DevDays2004 conference in Nanjing, the explanator has tried many times in order to demonstrate this function, but the Whidbey technology preview of the trend is not to face, and never willing to show its powerful function. Fortunately, this feature is available normally. ENCAPSULATE FIELD is a simple example: public class test {public Int i; public void f () {i = 3;}} Get it by picking Encapsulate Field on i: public class test {private INT i; public int i {get {return i;}
Set {i = value;}} public int f () {i = 3;}} It can automatically refer to the public member to the Private member and publicly public public properties, and update all references to Test.i, put them Change into the use of Test.i properties. Speaking of attributes, it can be mentioned that the visibility of attributes and indexes in C # 2.0 is, for example, it can be: public class test {private INT i; public int i {get {return {