SharePoint now has two major releases: SharePoint 2007 (with version 12.0) and SharePoint 2010 (with version 14.0). For developers, it's important to know which version they're working on. Sometimes developers need to working on both and write different code for different version.
Here are several ways to get SharePoint versions.
1. Get the version by SharePoint Object Model
This is easy for all developers, using Microsoft.SharePoint.Administration namespace and gets the version information by following code.
string version = SPFarm.Local.BuildVersion;
Console.WriteLine(version);
For SharePoint 2007, the output will be string begins with "12.0"; for SharePoint 2010, the output will be string starts with "14.0".