Download Visual Studio 2010
First, if you want it, go download Visual Studio 2010 now. If you're an MSDN Subscriber or WebSiteSpark/BizSpark member, you can download the final release now. If not, you can download a free trial or one of the free Express editions.
- Microsoft Visual Studio 2010 Professional
- Microsoft Visual Studio 2010 Ultimate
- Microsoft Visual Studio Team Foundation Server
I'm running the free Visual Web Developer 2010 Express on my netbook. You can install ASP.NET 4, ASP.NET MVC 2, and Visual Web Developer 2010 Express really quickly with the Web Platform Installer.
There's an excellent page on MSDN that's cherry-picked and categorized the best VS2010 content, but I've included my own list below.
What's new in Visual Studio 2010 and .NET 4?
Buttloads. Here's the things I'm digging most.
- What's new in Visual Studio 2010 - The IDE and Editor has really shaped up nicely. I've got it installed side-by-side with by existing VS2008 with no problems. There's hundreds of new things that I can't fit here, although some favorite IDE features of mine are:
- Multimonitor support - You can drag documents or toolboxes out of the IDE and onto other monitors.
- Zoom - You can "ctrl+scroll" (press the Ctrl key while scrolling your mouse wheel) to zoom in editors or diagrams. The editor has been totally rewritten using WPF.
- Navigate To - Hit "ctrl+comma" to navigate around your files, code, variables or methods much faster than Ctrl-F.
- Code-First Intellisense - You can hit Ctrl+Alt+Spacebar to tell toggle intellisense between regular Intellisense and a more TDD-friendly style that lets you create new classes and methods without getting hassled by the editor.
- Multi-Targeting Support - You can use VS2010 to create (target) .NET 2.0, 3.0, 3.5 or 4 applications. That means you can work on existing applications and get all the new IDE features while also working on new .NET 4 apps, all with the same IDE.
- ASP.NET 4 and ASP.NET MVC 2 are included in the box. WebForms now lets you create clean markup (no more tables) that's semantically correct and CSS-friendly, even for "legacy" controls and clientids that you control. ViewState is way smaller and can be turned on and off with greater granularity. Chart controls are included as well. On the MVC 2 side, we've got Areas, Strongly-typed helpers, Templated Helpers, field validation in models, and more. Both MVC and WebForms get all the core ASP.NET 4 improvements like a smaller web.config, the new <%: %> encoding syntax, extensible output caching, preloading of web apps, session state compression and routing for SEO-friendly URLs.
- Windows Communication Foundation (WCF) gets easier with a better configuration experience for services (bothSOAP and REST) as well as new functionality around routing and discovery.
- Windows Workflow (WF) gets a massive speed increase, the flowchart services, and it's way easier to make custom services than before. It's all in System.Activities.
- Entity Framework 4 and WCF Data Services 4 (OData) - Lots of improvements in the Data space, particularly in the Entity Framework 4. There's POCO support for Self-Tracking Entities, a DDL Generation Provider for creating databases based on a model, as well as lots of improvements to the designer. Don't forget WCF Data Services, I blogged about how easy it is to implement OData recently when I made an API for StackOverflow.
- What's new in C# 4 - C# gets a lot of new features in version 4 (or Visual C# 2010 if you like) like Dynamic Support (that's the DLR, built right in), Type Equivalence, and Covariance and Contravariance which makes generics much more flexible.
- What's new in Visual Basic 2010 - Jonathan Aneja discusses the coevolution strategy, and new features like Implicit Line Continuation, Statement Lambdas, Auto-Implemented Properties, Collection Initializers and how VB uses the DLR (Dynamic Language Runtime).
- New C++ and MFC Features - What? C++? Oh, yes. Pete Brown recently dipped his feet back into C++ with VS2010 and was shocked to find how easy it was to make a Ribbon Application with MFC. In this article, Samit Kumar talks about some of the new C++0x (that's see plus plus oh ex) core language features as well as major improvements in the standard library. VS 2010 enables lambda expressions, the auto keyword, rvalue references, static_assert, nullptr and decltype. It's not your father's C++. Well, maybe it is, if your dad is a ninja.
- What's new in WPF - Pete Brown has a fantastic and deep blog post on all the new WPF4 features. There's speed updates, a better designer, Windows 7 and touch support, text is crystal clear (not blurry!), a new datagrid, pixel shaders, the Visual State Manager, WPF Tracing support in VS2010 and more.
- MEF, the Managed Extensibility Framework comes with .NET 4. You use MEF to create extensible, compose-able applications. You don't need to download anything, it's integral to the framework and it works anywhere you like, including WinForms, WPF, ASP.NET or Silverlight.
- F# is in the box - F# ships with Visual Studio 2010. There's a good Introduction to Functional Programming for .NET Developers you should check out to see how you can use F# and how it will augment and complement your current language of choice.
- Concurrency, Threading and Parallelism - Check out the Parallel Computing Dev Center and how PLinq, the Task Parallel Library and the Coordination Data Structures work. Understand how to apply parallel patterns with .NET 4 with this awesome whitepaper. There's also major improvements in the Profiling Tools, including a Concurrency Visualizer for seeing how Multithreaded apps really behave. View their threads and how those threads migrate across cores.
- Team Foundation Server - Previously, installing TFS was, ahem, challenging. Today, I've seen people install TFS in 6 minutes with VS2010. Some say they can do it in 3. The point is, it's easy to install now along with lots more new features.
Also, there's a FREE e-Book called "Moving to Visual Studio 2010" that you might want to check out. It's an excerpt of a larger book that'll be coming from MSPress later this summer. It takes a interesting approach as it has three parts, moving from VS2003, moving from VS2005, and moving from VS2008. It's clever, actually. You start in the book on the version that you're currently on. If you're not familiar with versions like VS2008, you start at the beginning. Otherwise, you jump ahead. When you're done, you're ready to move to VS2010.
MSDN and Visual Studio 2010
When a new product launches, MSDN launches with updates and new features of its own. Here's a few things the folks at MSDN have been doing to support the launch.
- Better MSDN Search - Most people likely use a search engine to search MSDN, but if you do search from within MSDN, there are a number of new improvements. You can refine by source, saying only search blogs, or only search the library. There's also an OpenSearch provider so you can search the MSDN Library directly from within Windows itself.
MSDN Search also includes Metadata from the results to help you find right thing. For example, if a search turns up a CodePlex project, I can see type-specific details within search results:
- MSDN Subscriber Downloads Improvements - There's been lots of UX improvements including as-you-type filtering as well as filtering by platform (x64, etc) and language. I will very likely not need to download Quechua Windows, so now I don't need to see it.
- MSDN Library in Lightweight and ScriptFree - You can choose between three flavors of MSDN Library, Classic (the one with the treeview on the side), Lightweight (what I use) or ScriptFree. ScriptFree is great for mobile devices, and it's lightning fast anywhere. Lightweight is the new default and I like it because it features community annotations made to the library prominently on the left side as well as a tabbed interface for code sample languages. I blogged a preview of this work last year and included some charts and graphs showing the improvements in speed worldwide.
Inheritance is the idea that one class, called a subclass, can be based on another class, called a base class. Inheritance provides a mechanism for creating hierarchies of objects.
Inheritance is the ability to apply another class's interface and code to your own class.
Normal base classes may be instantiated themselves, or inherited. Derived classes can inherit base class members marked with protected or greater access. The derived class is specialized to provide more functionality, in addition to what its base class provides. Inheriting base class members in derived class is not mandatory.
Access Keywords
base -> Access the members of the base class.
this -> Refer to the current object for which a method is called.
The base keyword is used to access members of the base class from within a derived class:
Call a method on the base class that has been overridden by another method. Specify which base-class constructor should be called when creating instances of the derived class. A base class access is permitted only in a constructor, an instance method, or an instance property accessor.
In following example, both the base class, Person, and the derived class, Employee, have a method named Getinfo. By using the base keyword, it is possible to call the Getinfo method on the base class, from within the derived class.
// Accessing base class members
using System;public class Person
{protected string ssn = "444-55-6666";protected string name = "John L. Malgraine";public virtual void GetInfo()
{
Console.WriteLine("Name: {0}", name);
Console.WriteLine("SSN: {0}", ssn);}
}class Employee: Person
{public string id = "ABC567EFG";public override void GetInfo()
{// Calling the base class GetInfo method:base.GetInfo();
Console.WriteLine("Employee ID: {0}", id);
}
}class TestClass
{public static void Main()
{
Employee E = new Employee();
E.GetInfo();
}}
Output
Name: John L. Malgraine
SSN: 444-55-6666
Employee ID: ABC567EFG
Base class constructors can be called from derived classes. To call a base class constructor, use the base() constructor reference. This is desirable when it's necessary to initialize a base class appropriately.
Here's an example that shows the derived class constructor with an address parameter:
abstract public class Contact
{private string address;public Contact(string b_address)
{this.address = b_address;
}
}public class Customer : Contact
{public Customer(string c_address) : base(C_address)
{
}
}
In this code, the Customer class does not have an address, so it passes the parameter to its base class constructor by adding a colon and the base keyword with the parameter to its declaration. This calls the Contact constructor with the address parameter, where the address field in Contact is initialized.
One more example which shows how base-class constructor is called when creating instances of a derived class:
using System;public class MyBase
{int num;public MyBase()
{
Console.WriteLine("In MyBase()");
}public MyBase(int i)
{
num = i;
Console.WriteLine("in MyBase(int i)");
}public int GetNum()
{return num;
}
}public class MyDerived : MyBase
{static int i = 32;// This constructor will call MyBase.MyBase()public MyDerived(int ii) : base()
{
}// This constructor will call MyBase.MyBase(int i)public MyDerived() : base(i)
{
}public static void Main()
{
MyDerived md = new MyDerived(); // calls public MyDerived() : base(i) and// passes i=32 in base classMyDerived md1 = new MyDerived(1); // call public MyDerived() : base(i)}
}
Output
in MyBase(int i)
in MyBase()
The following example will not compile. It illustrates the effects of not including a default constructor in a class definition:
abstract public class Contact
{private string address;public Contact(string address)
{this.address = address;
}
}public class Customer : Contact
{public Customer(string address)
{
}
}
In this example, the Customer constructor does not call the base class constructor. This is obviously a bug, since the address field will never be initialized.
When a class has no explicit constructor, the system assigns a default constructor. The default constructor automatically calls a default or parameterless base constructor. Here's an example of automatic default constructor generation that would occur for the preceding example:
public Customer() : Contact()
{
}
When a class does not declare any constructors, the code in this example is automatically generated. The default base class constructor is called implicitly when no derived class constructors are defined. Once a derived class constructor is defined, whether or not it has parameters, a default constructor will not be automatically defined, as the preceding code showed.
Calling Base Class Members
Derived classes can access the members of their base class if those members have protected or greater access. Simply use the member name in the appropriate context, just as if that member were a part of the derived class itself. Here's an example:
abstract public class Contact
{private string address;private string city;private string state;private string zip;public string FullAddress()
{string fullAddress = address + '\n' + city + ',' + state + ' ' + zip;return fullAddress;
}
}public class Customer : Contact
{public string GenerateReport()
{string fullAddress = FullAddress();// do some other stuff...return fullAddress;
}
}
In above example, the GenerateReport() method of the Customer class calls the FullAddress() method in its base class, Contact. All classes have full access to their own members without qualification. Qualification refers to using a class name with the dot operator to access a class member-MyObject.SomeMethod(), for instance. This shows that a derived class can access its base class members in the same manner as its own.
More Tips regarding Inheritance:
- A static member cannot be marked as override, virtual, or abstract. So following is an error:
public static virtual void GetSSN()
- You can't call static methods of base class from derived class using base keyword.
In above example if you declare a static method as follows:
public class Person
{protected string ssn = "444-55-6666";protected string name = "John L. Malgraine";public static void GetInfo()
{// Implementation}
}
now you can't call this method using base.GetInfo() from derived class instead you have to call Person.GetInfo() from derived class.
Inside Static members we can access only static fields, methods etc.
Following example will give error, because we can't access name in GetInfo() because name is not static.
public class Person
{protected string ssn = "444-55-6666";protected string name = "John L. Malgraine";public static void GetInfo()
{
Console.WriteLine("Name: {0}", name);
Console.WriteLine("SSN: {0}", ssn);
}
}
Virtual or abstract members cannot be private.
- If you are not overriding a virtual method of base class in derived class, you can't use base class method by using base keyword in derived class. Also when you will create an instance of derived class, it will call derived class method and you will only be able to access base class method when you will create instance of base class.
- You can't decrease access level of a method in derived class when you are overriding a base class method in derived class, vice versa is possible.
Means you can make protected method of base class to public in derived class.
The "this" keyword refers to:
- the current instance for which a method is called. Static member functions do not have a this pointer. The this keyword can be used to access members from within constructors, instance methods, and instance accessors.
The following are common uses of this:
To qualify members hidden by similar names, for example:
public Employee(string name, string alias)
{this.name = name;this.alias = alias;
}
In above example, this.name refers to private variable name in the class. If we write name = name, then this will refer to argument name of the constructor Employee and not to private variable name in the class. In this case private variable name will never be initialized.
- To pass an object as a parameter to other methods, for example:
CalcTax(this);
To declare indexers, for example:
public int this [int param]
{get{return array[param];
}set{
array[param] = value;
}
}
It is an error to refer to this in a static method, static property accessor, or variable initializer of a field declaration.
In this example, this is used to qualify the Employee class members, name and alias, which are hidden by similar names. It is also used to pass an object to the method CalcTax, which belongs to another class.
// keywords_this.cs
// this exampleusing System;public class Employee
{public string name;public string alias;public decimal salary = 3000.00m;// Constructor:public Employee(string name, string alias)
{// Use this to qualify the fields, name and alias:this.name = name;this.alias = alias;
}// Printing method:public void printEmployee()
{
Console.WriteLine("Name: {0}\nAlias: {1}", name, alias);// Passing the object to the CalcTax method by using this:Console.WriteLine("Taxes: {0:C}", Tax.CalcTax(this));
}
}public class Tax
{public static decimal CalcTax(Employee E)
{return (0.08m*(E.salary));
}
}public class MainClass
{public static void Main()
{// Create objects:Employee E1 = new Employee ("John M. Trainer", "jtrainer");// Display results:E1.printEmployee();
}
}
Output
Name: John M. Trainer
Alias: jtrainer
Taxes: $240.00