Click here to Skip to main content
15,878,814 members
Home / Discussions / C#
   

C#

 
Questionvarchar(max) in database - how to put the size in ADO.NET Pin
Member 779716714-Apr-11 5:54
Member 779716714-Apr-11 5:54 
AnswerRe: varchar(max) in database - how to put the size in ADO.NET Pin
Ennis Ray Lynch, Jr.14-Apr-11 7:24
Ennis Ray Lynch, Jr.14-Apr-11 7:24 
GeneralRe: varchar(max) in database - how to put the size in ADO.NET Pin
Member 779716714-Apr-11 8:46
Member 779716714-Apr-11 8:46 
GeneralRe: varchar(max) in database - how to put the size in ADO.NET Pin
jschell14-Apr-11 9:38
jschell14-Apr-11 9:38 
GeneralRe: varchar(max) in database - how to put the size in ADO.NET Pin
Ennis Ray Lynch, Jr.14-Apr-11 9:52
Ennis Ray Lynch, Jr.14-Apr-11 9:52 
GeneralRe: varchar(max) in database - how to put the size in ADO.NET Pin
Prasanta_Prince15-Apr-11 6:32
Prasanta_Prince15-Apr-11 6:32 
AnswerRe: varchar(max) in database - how to put the size in ADO.NET Pin
jschell14-Apr-11 9:41
jschell14-Apr-11 9:41 
QuestionC# very basic basic` Pin
daveThawley14-Apr-11 2:29
daveThawley14-Apr-11 2:29 
Hi I am learning C# from the microsoft "Visual C# 2010 step by step". It seems good but I have got stuck on one example which I have attached to the bottom. The code works but I don't know how. It creates a class called point which holds an x and y o-ordinate. It then offers a method calle distanceTo whoch calculate the distance between the current objects x and y values and another objects x and y values. Dead easy but in the distance method there is a line which says

int xDiff = this.x - other.x;

Where other.x is the x value from the point object passed into the method and this.x is the x value of the current object . Since x is defined as private in the method how does the c compiler know about the data in the other.x field though ?

Any ideas ?

Cheers
Dave

Here is the code, the method first followed by the calling program ....



#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace Classes
{
class Point
{
private int x, y;
private static int objectCount = 0;

public Point()
{
this.x = -1;
this.y = -1;
objectCount++;
}

public Point(int x, int y)
{
this.x = x;
this.y = y;
objectCount++;
}

public double DistanceTo(Point other)
{
int xDiff = this.x - other.x;
int yDiff = this.y - other.y;
return Math.Sqrt((xDiff * xDiff) + (yDiff * yDiff));
}

public static int ObjectCount()
{
return objectCount;
}
}
}


-----------------------------------------------------------------------------


#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace Classes
{
class Program
{
static void DoWork()
{
Point origin = new Point();
Point bottomRight = new Point(1024, 1280);
Point one = new Point();
double distance = origin.DistanceTo(bottomRight);
Console.WriteLine("Distance is: {0}", distance);
distance = bottomRight.DistanceTo(origin);
Console.WriteLine("Distance is: {0}", distance);
Console.WriteLine("No of Point objects: {0}", Point.ObjectCount());
Console.ReadLine();
}

static void Main(string[] args)
{
try
{
DoWork();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
AnswerRe: C# very basic basic` Pin
Wayne Gaylard14-Apr-11 2:47
professionalWayne Gaylard14-Apr-11 2:47 
GeneralRe: C# very basic basic` Pin
fjdiewornncalwe14-Apr-11 3:08
professionalfjdiewornncalwe14-Apr-11 3:08 
AnswerRe: C# very basic basic` PinPopular
Richard MacCutchan14-Apr-11 2:50
mveRichard MacCutchan14-Apr-11 2:50 
AnswerRe: C# very basic basic` Pin
PIEBALDconsult14-Apr-11 2:51
mvePIEBALDconsult14-Apr-11 2:51 
AnswerRe: C# very basic basic` Pin
V.14-Apr-11 4:06
professionalV.14-Apr-11 4:06 
AnswerRe: C# very basic basic` Pin
Luc Pattyn14-Apr-11 4:13
sitebuilderLuc Pattyn14-Apr-11 4:13 
AnswerRe: C# very basic basic` Pin
daveThawley14-Apr-11 11:53
daveThawley14-Apr-11 11:53 
QuestionWhich is more usefull Abstract Class or Interface and Why? Pin
Prasanta_Prince13-Apr-11 19:26
Prasanta_Prince13-Apr-11 19:26 
AnswerRe: Which is more usefull Abstract Class or Interface and Why? PinPopular
David198713-Apr-11 19:34
David198713-Apr-11 19:34 
AnswerRe: Which is more usefull Abstract Class or Interface and Why? Pin
BobJanova13-Apr-11 23:17
BobJanova13-Apr-11 23:17 
GeneralRe: Which is more usefull Abstract Class or Interface and Why? Pin
Anubhava Dimri14-Apr-11 1:39
Anubhava Dimri14-Apr-11 1:39 
AnswerRe: Which is more usefull Abstract Class or Interface and Why? [modified] Pin
Pete O'Hanlon14-Apr-11 1:46
mvePete O'Hanlon14-Apr-11 1:46 
GeneralRe: Which is more usefull Abstract Class or Interface and Why? Pin
David198714-Apr-11 2:12
David198714-Apr-11 2:12 
GeneralRe: Which is more usefull Abstract Class or Interface and Why? Pin
Pete O'Hanlon14-Apr-11 2:19
mvePete O'Hanlon14-Apr-11 2:19 
GeneralRe: Which is more usefull Abstract Class or Interface and Why? Pin
Pete O'Hanlon14-Apr-11 2:24
mvePete O'Hanlon14-Apr-11 2:24 
GeneralRe: Which is more usefull Abstract Class or Interface and Why? Pin
David198714-Apr-11 2:30
David198714-Apr-11 2:30 
GeneralRe: Which is more usefull Abstract Class or Interface and Why? Pin
Pete O'Hanlon14-Apr-11 2:42
mvePete O'Hanlon14-Apr-11 2:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.