Using classes as data types


I am trying to understand why and when to use classes as data types.

consider this: (prob not a good example)

class Program { public Hello hello; //why and when to use something like this. static void Main(string[] args) { Hello h = new Hello("Hello"); } } public class Hello { public string Print { get; set; } public Hello(string print) { Print = print; Console.WriteLine(Print); } } 

Above there are two scenarios: One – class Hello "is-part-of" (composition) of class Program. Two- class Hello is being used as a data type ( would I say its being used as a data type?). I thought Second scenario was also called composition. Can someone explain scenario two, about Why, when and how it would be used?

Thank you

by NonaBona via /r/csharp

Leave a Reply