|
There is no instance associated with a static keyword. Thus using this makes no sense.
|
|
|
|
|
a class can be seen as a template to create objects with. Your class Car eg can have multiple instances like this:
Car lamborghini = new Car();
Car ferrari = new Car():
if you declare a normal variabel like color eg. you can assign a different color to each instance you created.
Car lamborghini = new Car("pitch black");
Car ferrari = new Car("pomegranate red"):
lamborghini.color = "Le Mans blue";
ferrari.color = "Purple";
However, if you assign a static variabel (or function) you cannot assign it to one or the other object. Suppose we assign a static variabel type to car and give it the value "vehicle", neither the lamborghini nor ferrari object has that value, it´s the class Car that has that value. That´s why you access it like this:
String cartype = Car.type;
static members are attached to the class, not to the instance of that class. this points the its own instance.
Hope this helps.
(PS: I want against OO rules here to simplify things, but don´t go making things public like that )
|
|
|
|
|
Hello, I'm very new to C# programming, in fact I only started about 3 months ago and have no formal training, only on the job. I have the need to draw a line on a windows form, that follows a moving point. there are actually 2 points I need to follow creating 2 separate lines. below is the code that creates the moving points:
private void timer1_Tick(object sender, EventArgs e)
{
Double X1, Y1, A, B;
int x2, y2, c, d;
X1 = 300 + (708 * (30 - simNumber14.OldValue) / 30);
Y1 = 495 - (354 * simNumber6.OldValue / 31.5);
x2 = (int)X1;
y2 = (int)Y1;
tietrack.Location = new Point(x2, y2);
A = 297 + (711 * (30 - simNumber14.OldValue) / 30);
B = 704 - (158 * (Math.Max((simNumber3.OldValue - 19.49), 0))/ 15);
c = (int)A;
d = (int)B;
tietrack2.Location = new Point(c, d);
}
A timer variable (simNumber14.OldValue) counts down from 30 minutes to 0, and the points move back to their origins and start to track again. At which point the lines they created over the first 30 minutes would be gone and new ones would start. the process would repeat itself as long as it was asked to. I can't imagine it would be that hard, but I'm very new to this.
Thanks
|
|
|
|
|
You just need to override the OnPaint[^] method in your form, and draw the lines between each current point, or set of points as appropriate.
Veni, vidi, abiit domum
|
|
|
|
|
Thanks, but I'm so new to C#, and Visual Studio in general, that I would need a little more detail on how to implement it, and what the specific syntax would be, maybe an example. I have been trying to research what you've said, thanks for pointing me in the right direction.
|
|
|
|
|
Davebandit wrote: Thanks, but I'm so new to C#, and Visual Studio in general, that I would need a little more detail on how to implement it, and what the specific syntax would be, maybe an example. There's a How to[^] on MSDN. It's from a section on graphics programming[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks, I'll take a look at it.
|
|
|
|
|
Davebandit wrote: I'm so new to C#, and Visual Studio in general Then maybe, you would be better spending some time working through some of the basics first to get your brain properly attuned to the C# and .NET concepts. Charles Petzold has written an excellent introductory book, titled .NET Book Zero[^], and MSDN offer a set of useful tutorials[^]. Add to that the wealth of information in the CodeProject articles[^] and you have plenty of help.
Veni, vidi, abiit domum
|
|
|
|
|
I am new to C#. I have in mind a nested class structure. First of all. Is this optimal? Secondly, please could someone provide the coded outline of this structure so that I can work on filling and coding the functions.
class Z
class Y
class X
class V
|
|
|
|
|
I'm really short of time on this task.
The task is to take a csv file.
Process a list of x,y specified coordinate points.
Work out the distance between all these coordinate points.
Print results to file
Ta
|
|
|
|
|
Is this for an interview or something?
|
|
|
|
|
yes. got it in one. 10 years since i coded in C# and I underestimated the task.
|
|
|
|
|
Well, time management is part of the interview process for projects like this. Do you really need me to tell you how you've done on that part?
Nobody is going to do your work for you.
|
|
|
|
|
Member 10266494 wrote: short of time on this task
So you left doing your homework assignment until the last minute and expect us to do it for you?
|
|
|
|
|
I would avoid nested classes whenever I can, but that's just my personal opinion.
|
|
|
|
|
This is the third time you have asked what is basically the same question. Nested classes is not the answer, as you obviously don't understand what they are. Take Pete O'Hanlon's advice and go and work through Charles Petzold's free book. You cannot learn how to write good code by repeating the same question in a forum like this.
Veni, vidi, abiit domum
|
|
|
|
|
I don't know where I made mistake.I checked everything !! but this error happened :
"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
thank you in advance.
int i = 1;
int RowNo = 0;
int CellNo = 0;
foreach (DataGridViewRow row in Firstdgv.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (i > Finaldgv.Columns.Count)
break;
Finaldgv.Rows[RowNo].Cells[CellNo].Value = cell.Value;
i++;
CellNo++;
}
RowNo++;
i = 1;
CellNo = 0;
}
|
|
|
|
|
At a guess - and that's about it it can be from that little code - you haven't allocated any rows or columns in the destination DGV, or you are trying to access different sized DGVs.
So when you try to access it's Rows collection via an index:
Finaldgv.Rows[RowNo] Or the resulting DataGridViewRow Cells collection:
Finaldgv.Rows[RowNo].Cells[CellNo] It complains becasue it doesn't exist.
Start this way: put a breakpoint on the if line, and single step through from there - look at the variables as you go, and look for null values. (It may help to "break out" the line assigning the row so that each part to the left of a "." is a separate variable - you don't need to, but it makes it easier to see without complex use of the debugger)
DataGridViewRow row = Finaldgv.Rows[RowNo];
DateGridViewCell cell = row.Cells[CellNo]; And so forth.
PS: Keep an eye on the value of i ...
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
First, the value of i isn't doing anything according to your code, you should be able to remove it and use CellNo instead. Personally I'd move the declaration of CellNo inside the first foreach loop, that way you can also remove the line CellNo = 0; at the end.
int RowNo = 0;
foreach (DataGridViewRow row in Firstdgv.Rows)
{
int CellNo = 0;
foreach (DataGridViewCell cell in row.Cells)
{
if (CellNo >= Finaldgv.Columns.Count)
break;
Finaldgv.Rows[RowNo].Cells[CellNo].Value = cell.Value;
CellNo++;
}
RowNo++;
}
If this doesn't fix your problem (I doubt it will) you need to figure out which of the two indexes is wrong - you can put a breakpoint on, or you could temporarily amend Finaldgv.Rows[RowNo].Cells[CellNo].Value = cell.Value; to:
var tempRow = Finaldgv.Rows[RowNo]
var tempCell = tempRow.Cells[CellNo]
tempCell.Value = cell.Value
And see which line breaks - my initial gut reaction is you have no rows.
|
|
|
|
|
my dear friend ,at first I am so appriciate for your attention.
I revised the code as you said but the error still exist !!
the error happens in the "***" line
when the RowNo=1 error occurs !!
int RowNo = 0;
foreach (DataGridViewRow row in Firstdgv.Rows)
{
int CellNo = 0;
foreach (DataGridViewCell cell in row.Cells)
{
if (CellNo >= Finaldgv.Columns.Count)
break;
var tempRow = Finaldgv.Rows[RowNo]; ***
var tempCell = tempRow.Cells[CellNo];
tempCell.Value = cell.Value;
CellNo++;
}
RowNo++;
}
|
|
|
|
|
When you put a break point on var tempRow..., and inspect the value, what do you find? The thing that stands out to me here is that you have an assumption that Finaldgv has more than one row, and there's no guarantee that this is the case.
|
|
|
|
|
I want to copy Firstdgv rows to Finaldgv rows.So how can I refer to the second,third and... rows in Finaldgv in order to copy the second ,third and .... Firstdgv rows .
I think your assumption is right.but what should I do?
|
|
|
|
|
If you are trying to copy the values from one grid into another (and I'm assuming the second one is empty), then you Add the rows into the other grid.
|
|
|
|
|
thank you my friend it works
thank you ALL
|
|
|
|
|
You're welcome. I'm glad I could be of service.
|
|
|
|