|
HI
i am new in c#
plz tell me
how to define the below in c#
struct link
{
int info;
link *next
};
struct link *start=new link;
Parshant
|
|
|
|
|
Well, you can't have a pointer, so
struct link
{
int info;
link next
};
struct link start=new link();
You don't want to be writing linked list classes tho, you should just use the ones built into the framework.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
sir plz tell me how with abov e.g
|
|
|
|
|
I don't understand - I converted your struct to C#, what else did you need ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I guess he tried to compile your code and it failed. It doesn't work because you're trying to create an instance of the struct as a member of the very struct you're defining, so it becomes kinda like an infinite recursive definition.
|
|
|
|
|
Structs works differently in C# than in C. In C# a struct is a value type and a class is a reference type, while in C a struct is just a definition and the type depends on how you use it.
As you want to have references to your objects you would want it to be a reference type, so you use a class:
class Link {
public int info;
public Link next;
}
Link start = new Link();
---
b { font-weight: normal; }
|
|
|
|
|
Good point
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
How to create report in VS.Net 2003 using C#
namita dang
|
|
|
|
|
How to create report in VS.Net 2003 using C#
Jitendra Tyagi
|
|
|
|
|
|
Hello
how to make image transparent in Win Appl in c#.NET so that I can see controls behind it,what r the properties that I have to changes for it.
Thanking you
Yogesh_T
|
|
|
|
|
how to map an object of the so called real life to programming world.
Say there is a car. How can we take this to programming world. Car with wheel, engine, etc. Car
can move without even doors, it's movement will be effected if one wheel is with low air pressure.
etc.
Here car should be an object, wheel also an object. Car has wheels, doors etc., but wheel has different
impact than doors as far as motion is concerned.
Can someone help me visualize this object to OOP?
|
|
|
|
|
You can't, not really. Every car has some stains on the seats, are you going to bother to map those ? Chips in the paint ? Oil on the engine ? No. You choose the bits that are important to what you want to write, and you map those to classes. Getting it exactly the way it is in the real world is not the point, mapping the bits you want to interact with so they work smoothly in your program, is.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
>>You can't, not really.
Help me to some extent.
>>Every car has some stains on the seats, are you going to bother to map those ?
Yes, anything with some volume should be able to interact with the seat. There some physics rules should come handy. and so on
>> Chips in the paint ?
Yes, again some interaction with the environment. How environment can effect the car?
>> Oil on the engine ?
Yes, of course. Help me outhere as well.
>> No. You choose the bits that are important to what you want to write, and you map those to classes. Getting it exactly the way it is in the real world is not the point, mapping the bits you want to interact with so they work smoothly in your program, is.
'm want to simulate the max possible.
|
|
|
|
|
sinanju wrote: 'm want to simulate the max possible.
Why ? Are you writing a game ? Why would you care if there's oil ON the engine ( under the hood ), or chips in the paint, or stains in the seat ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
public class Car
{
private Wheel [] wheels;
private Door [] doors;
private SteeringWheel steeringWheel;
private GearBox gearBox;
private Engine engine;
public Car()
{
wheels = new Wheel[4];
doors = new Door[4];
gearBox = new GearBox();
steeringWheel = new SteeringWheel();
engine = new TwoLitreEngine();
}
public void Start()
{
gearBox.SetNeutral();
while(!engine.Started)
{
engine.EngageStarterMotor();
}
engine.DisengageStarterMotor();
}
}
You can go on ad infinitum implementing whatever objects you want to define. The above code relies on an implementation of Wheel , Door , GearBox , and SteeringWheel . Also, a base class called Engine and an implementation of it called TwoLitreEngine is defined.
|
|
|
|
|
Car a is a very large object to map.
This class is a decent basic overview, but due to the massive variations between types of car, you could consider making it abstract and defining specific types of car.
This implementation assumes that a car will have 4 wheels (some had 3), and 4 doors (some have 2), and does the book count as a door? Manual or Auto gearbox, etc.
e.g.
public class VauxhallCorsa : public Car
{
public VauxhallCorsa()
{
wheels = new Wheel[4];
doors = new Door[3];
gearBox = new ManualGearBox();
steeringWheel = new SteeringWheel();
engine = new OneLitreEngine();
}
}
|
|
|
|
|
wheelerbarry wrote: This class is a decent basic overview, but due to the massive variations between types of car, you could consider making it abstract and defining specific types of car.
Considering the OP isnt even proficient in defining objects yet, I tried to stear clear of the obvious abstractions.
Of course, the base class should be called Vehicle allowing definition of a Boat (no wheels, still with engine), Bycycle (2 wheels, no engine/gearbox) etc etc etc.
My answer was simply to give a basic layout of a class, which i think is what the OP asked for!
|
|
|
|
|
Hi,
I am working on a Windows based project using C#.
Using VS 1.1 version.
I am using a datagrid.I have a problem, that if the user
modifies the data in the grid, how will we come to know
that there is a change in value in the grid.
I am not using DataSet...i am using a DataGrid
Plz help me to solve the prob,since i am new to C#
Thanks in advance
Regards,
Vaishali
|
|
|
|
|
how you fill the rows in the grid , what is your data source ??
Tamimi - Code
|
|
|
|
|
hi,
i made a access database and view it on a datagrid, i did this by using the datasource,ea in the toolbar. i can add rows to my database, but i cant find the way to delete one. i can delete one in the datagrid but it is not gone in my database. i tried this code:
try
{
tabel1TableAdapter.Update(db1DataSet.tabel1);
db1DataSet.AcceptChanges();
// refresh after the delete
this.tabel1TableAdapter.Fill(this.db1DataSet.tabel1);
Application.DoEvents();
}
catch (System.Exception ex)
{
db1DataSet.RejectChanges();
lbl_error.Text= ex.Message;
}
but i get an error because there is nog valid delete command,
so i looked that op, now i dont know how to create a deletecommand using the tableadapter that was build by the wizard in the beginning by using the toolbar.
can anybody help, or is there another way to delete items without having an error
thx
|
|
|
|
|
See here[^] maybe it is some helpful to you
|
|
|
|
|
Hello Everyone,
I've got a little problem that I can't seem to find a straight answer to so I'm throwing it out there for you guys to take a stab at it.
I have a UserControl being developed that has two panel controls.
I have already set the designer attribute to allow child controls at design time
<br />
[DesignerCategoryAttribute("Component")]<br />
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]<br />
[ToolboxBitmap(typeof(XPanel),"Image1.bmp")]<br />
public partial class XPanel : UserControl<br />
now i can drag a control on it as is no problem.
what i need to do is when a control is added send it to one of the internal panel's controls collection.
i've tried using the ControlAdded and ControlRemoved events to accomplish this
<br />
private void XPanel_ControlAdded(object sender, ControlEventArgs e)<br />
{<br />
this.DockingPanel.Controls.Add(e.Control);<br />
}<br />
<br />
private void XPanel_ControlRemoved(object sender, ControlEventArgs e)<br />
{<br />
this.DockingPanel.Controls.Remove(e.Control);<br />
}<br />
when i drag a control on to it now i get a pop up in visual studio that says
'child' is not a child control of this parent
if someone could tell me what i'm doing wrong or what i'm missing it would be greatly appreciated.
Ryan Strope
|
|
|
|
|
Hello,
I think the problem is the ControlRemoved EventHandler.
If you add a Control the code in the ControlAdded EventHandler has the effect, that also the code in ControlRemoved is going to be worked threw.
Maybe the solution is to set a boolean flag in the ControlAdded code.
private bool comesfromdesigner=true;
Try that:
private void XPanel_ControlAdded(object sender, ControlEventArgs e)
{
comesfromdesigner = false;
this.XPanel.Controls.Remove(e.Control);
this.DockingPanel.Controls.Add(e.Control);
comesfromdesigner = true;
}
private void XPanel_ControlRemoved(object sender, ControlEventArgs e)
{
if(comesfromdesigner)
this.DockingPanel.Controls.Remove(e.Control);
}
But I'm not sure if you need the ControlRemove code at all!
All the best,
Martin
|
|
|
|
|
Thanks for the effort but no dice there,
tried that and it still didn't work.
Sorry for the short response on the way into the office
Ryan Strope
|
|
|
|