• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

New Programmer Assistance Here- C#

Messages
11
Country
jamaica
Now Im a new person to all this coding buisness and i would like some Help

class Aircraft
{
public string TypeOfPlane;
public string Model;
public int PilotsRequired;
public int FuelLimit;
public int Price;

}

//Do i have to make a new class to input Values such as this?

class Boeing747
{

Aircraft.TypeOfPlane = "Boeing"
Aircraft.Model = "747'
Aircraft.PilotsRequired = "3"
Aircraft.FuelLimit = "10"
Aircraft.Price = "300"

}

// I would like to ask did i have to make a new class to input values or could I
// Have done it in the same class



Ok my last question now is how do I display these Values with their types when a button is clicked For example:

the button is called : Boeing 747

I want it to display all properties of the class Boeing747 and i would like it to display like:

Type Of plane: Boeing

Instead of:

Aircraft.TypeOfPlane = "Boeing"


Thanks guys! I need all the help I can get so I can develop some new programs!
 
I think you need to do some research on object oriented programming and C#

Use 'google' or similar - there are a number of sites out there with basic introductions to C#. Also a lot of good books.

To answer your question you would not need a separate class for the 747 since it is an Aircraft. You would only need to make a separate class if you needed to add properties that are required by the 747 that are not in the base class. In that case you would use inheritance and use the Aircraft class as the base class.
You Boeing747 class would not work in any case.

To input to your Aircraft Class you first need to instantiate it:

Aircraft aircraft = new Aircraft();

Then you can assign values to it:

Code:
aircraft.TypeOfPlane = "Boeing";
aircraft.Model = "747";
aircraft.PilotsRequired = 3;
aircraft.FuelLimit = 10;
aircraft.Price = 300;
 
Last edited:
In c# you can declare Aircraft as an abstract class:

public abstract class Aircraft
{
public string TypeOfPlane;
public string Model;
public int PilotsRequired;
public int FuelLimit;
public int Price;
}

An abstract class is a base class that cannot be directly instanciated.
Then, you can create derived classes that inherit from Aircraft

public class Boeing747 : Aircraft
{
TypeOfPlane = "Boeing"
Model = "747'
PilotsRequired = "3"
FuelLimit = "10"
Price = "300"
public int NumberOfJetEngines = 4.
}

Any field, property or method defined in the base class is available in the derived class. and, in the derived class, you can add new fields, properties and methods. An the example, I have added a new field, NumberOfJetEngines.

Furthermore, You can derive a class from a derived class, such as
public class Boeing747_400 : Boeing747{ ...}
 
Thank you guys!

But one thing missing though When the Button Boeing 747 is clicked how do i display The properties?

Really that is much more involved. Have you created a Form and added a button? Have you added any text boxes or labels to display in?

You need to assign an event handler to the Button_Click Event and from there display the values in the text boxes or labels.

It is not at all clear what you are trying to do - perhaps you can tell us what application you are trying to create and what it is supposed to do?
 
I am just trying to create a program to display the properties of different Aircraft.

All i want to learn to do now is how to grab the properties out of the Class airplanes from the object Aircraft and display it.

How do I do this?
 
What development tool are you using Visual Studio Express or something else.

I ask again if you know how to create a form and put controls on it?
 
OK

A button has a Click Event. You need to create a handler for that event which you can do in the properties window of the button.

Add a text box for each property you want to display. These hold the data from the fields


Code:
Aircraft aircraft = new Aircraft();  

aircraft.TypeOfPlane = "Boeing";
aircraft.Model = "747";
aircraft.PilotsRequired = 3;
aircraft.FuelLimit = 10;
aircraft.Price = 300;

I assume aircraft is a field for your Form and you are assigning values in the Form load event or constructor.

Now in the event handler for the button use something like:

Code:
typeOfPlaneTextBox.Text = aircraft.TypeOfPlane;
modelTextBox.Text = aircraft.Model;
and so on
 
Thank you so much!

I will continue to study the Object-Oriented approach so I can bring more advanced questions That will enchance my skills but for now thank you for your assinstance Mr.Scruffy
 
I would definitely recommend getting a good book on C#, and learning about programming in general. Something akin to C++ Primer (but for C#) would be ideal.
 
I already have one its a Highly detailed ebook from MSDN

Just to Verify is the code like this?:

class Aircraft
{

public string TypeOfPlane;
public string Model;
public int PilotsRequired;
public int FuelLimit;
public int Price;

Aircraft boeing = new Aircraft();

boeing.TypeOfPlane = "Boeing";
boeing.Model = "747";
boeing.PilotsRequired = 3;
boeing.FuelLimit = 10;
boeing.Price = 300;

typeOfPlaneTextBox.Text = boeing.TypeOfPlane;
modelTextBox.Text = boeing.Model;
PilotsReq.Text = boeing.PilotsRequired;
FuelLimit.Text = boeing.FuelLimit;
Price.Text = boeing.Price;

}
 
Last edited:
No - you have put everything inside the class. I am sorry but I think you need to do some reading on basic programming with C# before asking any more questions here.

Are you actually trying any of this out in Visual Studio?
 
What's the difference between C, C++ and C# anyway?
Same language, different dialects (i.e. supported functions)?
"Know one, know 'em all (in essence at least)?
 
What's the difference between C, C++ and C# anyway?
Same language, different dialects (i.e. supported functions)?
"Know one, know 'em all (in essence at least)?

Ahhh.........................:eek:

Well apart from the fact that they use vaguely similar syntax they are all quite different. In fact Java looks closer to C# than C does. They do all fall into the group of languages that use ; as a line terminator and {} to delimit code blocks. Otherwise C# is in the group of languages that have a managed memory model. In theory the programmer should not need to worry about recovering unused and memory. C, C++ memory management and garbage collection is left to the developer
 
Last edited:
Hello Again,

Back with my Noob Questions, Well Im currently on C# trying to Figure this out while im reading the MSDN c# for kids Book(To get use to the terms) and I have stumbled across a Little tiny Problem

http://s16.postimg.org/suvh5z7rp/Capture.png

It keeps saying "Is a Field but is used as A type"


Why is it the Animal Object Named Percy is Red Lined and why is the = sign also have the red line. Everything went fine so fare Im at Integers and Booleans.

Please Help.
 
Last edited:
Hello Again,

Back with my Noob Questions, Well Im currently on C# trying to Figure this out while im reading the MSDN c# for kids Book(To get use to the terms) and I have stumbled across a Little tiny Problem

http://s16.postimg.org/suvh5z7rp/Capture.png


Why is it the Animal Object Named Percy is Red Lined and why is the = sign also have the red line. Everything went fine so fare Im at Integers and Booleans.

Please Help.

I think the problem is mis-matched braces. This can give rise to red lines in odd places. However the last brace is red which indicates either a missing brace or one two many
 
Last edited:
Back
Top