blackneos940
Active Member
So anywho, this post pertains to Linux, but also to any OS that can run Mono or .NET Framework. It's a basic C# Program I got from a YouTube video teaching C#.
First, the Code...
I'm having trouble knowing when to use public and private, and when to call Classes.
And in particular... Why is public Animal() in there twice? That's seriously confusing..... I feel that if I can understand these things, I can become much better at C#, and OOP in general.
It Compiles and runs under Mono and .NET (it doesn't use Windows Forms, and is a CLI Program). :3 Thanks for any help guys. :3 Have a good one..... :3

Code:
using static System.Console;
namespace Classes
{
class Animal
{
//Class Constructors
public static int count;
public string name;
public int age;
public float happiness;
public Animal()
{
//Class Methods
name = "Spotty";
age = 3;
happiness = 0.5f;
count++;
}
public Animal(string _name, int _age, float _happiness)
{
name = _name;
age = _age;
happiness = _happiness;
count++;
}
public void Print()
{
WriteLine("Name: " + name);
WriteLine("Age: " + age);
WriteLine("Happiness: " + happiness);
}
}
class Main_Class
{
public static void Main(string[] args) //This is a Method called "Main". It is called when the Program starts.
{
Animal dog = new Animal();
dog.Print();
Animal cat = new Animal("Mr. Beans", 2, 0.08f);
cat.Print();
WriteLine("Num of Animals: " + Animal.count);
ReadKey();
}
}
}
I'm having trouble knowing when to use public and private, and when to call Classes.

