Current location: Hot Scripts Forums » Programming Languages » Windows .NET Programming » nested class constructors


nested class constructors

Reply
  #1 (permalink)  
Old 06-01-06, 04:18 AM
stealth04 stealth04 is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
nested class constructors

Hi,
I'm quite new in C# and I don't have many experiences with OOP. I would like to create a simple radar simulation.
At the beginning I created a moving object class this way:
...
Code:
class MovingObj
{
     public class Position
     {
          public double x;
          public double y;
          public double z;

          public Position(double x, double y, double z)
          {
               this.x = x;
               this.y = y;
               this.z = z;
          }
...
I compiled this as library class. Then I created another class from which I would like to instantiate the moving object properties and I don't know exactly how to do that.
I have tried to do like this:
MovingObj a = new MovingObj();
...
a.Position(1,2,3);
...

but this isn't correct.
I would be very thankful if anyone could tell me how to set position properties in this case.

Regards,
Niko
Reply With Quote
  #2 (permalink)  
Old 06-15-06, 02:47 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
You can do the following:

Code:
public class MovingObj
{
   //
   // TODO: Add constructor logic here
   //
   private double x;
   private double y;
   private double z;
   public double Position(double x, double y, double z)
   {
	 this.x = x;
	 this.y = y;
	 this.z = z;
	 return this.x + this.y + this.z;
   }
}
And then call it like this (I realize you didn't want to add the coordinates up together, but I did that just for demonstration purpose):

Code:
 MovingObj a = new MovingObj();
 txtSum.Text = a.Position(1,2,3).ToString();
A sample project for this is attached bellow.
Attached Files
File Type: zip SimpleObjectInstance.zip (35.0 KB, 129 views)
__________________
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A little help with a class please :) HairySpider PHP 2 04-10-06 04:06 AM
Javascript Function Class question vincentdehaan JavaScript 0 07-02-05 09:34 AM
PHP global variables don't work inside a class wizkid PHP 4 12-20-04 03:31 PM
class designs:air traffic controller system lore00 Everything Java 0 08-09-04 10:25 AM


All times are GMT -5. The time now is 02:16 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.