Question Type Point in System.Windows

Ruth

New member
Joined
Jul 2, 2011
Messages
1
Programming Experience
Beginner
In the book "Programming C# 4.0", the type Point is declared in System.Windows, but the Visual Studio Express 2010 compiler consider it to be an error.
The code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

class Firefighter
{
public string Name { get; set; }
public void ExtinguishFire()
{
Console.WriteLine("{0} is putting out the fire!", Name);
}
public void Drive(Firetruck truckToDrive, Point coordinates)
{
if (truckToDrive.Driver != this)
{
return;
}
truckToDrive.Drive(coordinates);
}

This is the message
Error 1 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)
Error 2 The type or namespace name 'Point' could not be found (are you missing a using directive or an assembly reference?)
 

JohnH

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
868
Location
Norway
Programming Experience
10+
There is a Point structure defined in System.Windows namespace (in WindowsBase assembly) used for WPF applications, and one in System.Drawing namespace used in Windows Forms applications and otherwise for GDI+ drawing with System.Drawing assembly. So you are probably looking at a WPF example but have created a winforms applications.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,225
Location
Sydney, Australia
Programming Experience
10+
If the error message says that Windows does not exist in System then I don't think that that is even a WinForms app, but rather a Console app. As JohnH says, you should be using the System.Drawing.Point structure unless you're using WPF. A Console app will not have a reference to System.Drawing.dll by default, so you will have to add that yourself and then import the namespace.
 
Top Bottom