Error with Tuple in C # 2008
I made a program in C # 2010 and my code contains a Tuple, but when I put my program in C # 2008, it doesn't recognize it and the error appears:
"The type of namespace name 'Tuple' could not be found"
So, I don't know how to do it, this is the line of code where the error occurs:
private List<Tuple<Point, Point>> lines = new List<Tuple<Point, Point>>();
Please, help.
EDIT
Basically this is my code at the moment, which does not compile due to an error:
public partial class Form1 : Form
{
private bool isMoving = false;
private Point mouseDownPosition = Point.Empty;
private Point mouseMovePosition = Point.Empty;
private List<Tuple<Point, Point>> lines = new List<Tuple<Point, Point>>();
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
var g = e.Graphics;
if (isMoving)
{
g.Clear(pictureBox1.BackColor);
g.DrawLine(Pens.Black, mouseDownPosition, mouseMovePosition);
foreach (var line in lines)
{
g.DrawLine(Pens.Black, line.Item1, line.Item2);
}
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
isMoving = true;
mouseDownPosition = e.Location;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isMoving)
{
mouseMovePosition = e.Location;
pictureBox1.Invalidate();
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (isMoving)
{
lines.Add(Tuple.Create(mouseDownPosition, mouseMovePosition));
}
isMoving = false;
}
}
So, I need to change or make Tuple work in VS C # 2008 as well as 2010,
thank
source to share
The class is Tuple
not in the pre-v4 framework, but here is a simplified version that should suit most of your needs:
public class Tuple<T,U>
{
public T Item1 { get; private set; }
public U Item2 { get; private set; }
public Tuple(T item1, U item2)
{
Item1 = item1;
Item2 = item2;
}
}
public static class Tuple
{
public static Tuple<T, U> Create<T, U>(T item1, U item2)
{
return new Tuple<T, U>(item1, item2);
}
}
you can easily add classes to have Tuples with more than two parameters
source to share
Tuple is new to .NET Framework 4. Visual Studio only targets .NET Framework 3.5 to the latest version. This way you are targeting a Framework that does not contain a Tuple class and will not compile.
If you really need this in Framework 3.5 / VS2008, it wouldn't be too difficult to write your own Tuple class to compile the existing code under that version (assuming you're not using any other 4.0 specific).
source to share