diff --git a/Solution/UsingActualMethods.cs b/Solution/UsingActualMethods.cs new file mode 100644 index 0000000..4a075b0 --- /dev/null +++ b/Solution/UsingActualMethods.cs @@ -0,0 +1,23 @@ +//Using actual methods instead of Getter Setters +using System; +public class Person { + private string name; + private int age; + + public void IntializePersonDetails(string name, int age) { + this.name = name; + this.age = age; + } + + public void DisplayPersonDetails() { + Console.WriteLine($"Name of the Person: {name}\nAge of the Person: {age}"); + } +} + +public class ProfileManager { + public static void Main() { + Person person = new Person(); + person.IntializePersonDetails("Poyam", 22); + person.DisplayPersonDetails(); + } +} \ No newline at end of file diff --git a/Solution/UsingConstructors.cs b/Solution/UsingConstructors.cs new file mode 100644 index 0000000..b089a8a --- /dev/null +++ b/Solution/UsingConstructors.cs @@ -0,0 +1,28 @@ +//Using Constructor Initialization +using System; + +public class Person { + private string name; + private int age; + + public Person(string name, int age) { + this.name = name; + this.age = age; + } + + public string FetchName() { + return name; + } + + public int FetchAge() { + return age; + } +} + +public class ProfileManager { + public static void Main() { + Person person = new Person("Poyam", 22); + Console.WriteLine("Name is : " + person.FetchName()); + Console.WriteLine("Name is : " + person.FetchAge()); + } +} \ No newline at end of file diff --git a/Solution/UsingReadOnlyProperties.cs b/Solution/UsingReadOnlyProperties.cs new file mode 100644 index 0000000..515384d --- /dev/null +++ b/Solution/UsingReadOnlyProperties.cs @@ -0,0 +1,20 @@ +//Using Read-only Properties +public class Person { + public string Name { get; } + public int Age { get; } + + public Person(string name, int age) { + Name = name; + Age = age; + } +} + +class ProfileManager { + static void Main(string[] args) { + Person person = new Person("Poyam", 22); + + // Accessing properties + Console.WriteLine("Name of the Person: " + person.Name); + Console.WriteLine("Age of the Person: " + person.Age); + } +} \ No newline at end of file