diff --git a/Problem Statement- GettersSetters.txt b/Problem Statement- GettersSetters.txt new file mode 100644 index 0000000..9d4b860 --- /dev/null +++ b/Problem Statement- GettersSetters.txt @@ -0,0 +1,24 @@ +// What are the ways you can remove Getters/Setters from below code. Find at least 3 ways for that. It's just an example you can write code in your favorative language. + +public class Person { + private String name; + private int age; + + // Getter methods + public String getName() { + return name; + } + + public int getAge() { + return age; + } + + // Setter methods + public void setName(String name) { + this.name = name; + } + + public void setAge(int age) { + this.age = age; + } +} diff --git a/UsingConstructorInitialization.cs b/UsingConstructorInitialization.cs new file mode 100644 index 0000000..f6b2a80 --- /dev/null +++ b/UsingConstructorInitialization.cs @@ -0,0 +1,14 @@ +namespace RemoveGetterSetterWithConstructorInitialization +{ + public class Person + { + public string Name { get; } + public int Age { get; } + + public Person(string name, int age) + { + Name = name; + Age = age; + } + } +} diff --git a/UsingFunctions.cs b/UsingFunctions.cs new file mode 100644 index 0000000..47da18e --- /dev/null +++ b/UsingFunctions.cs @@ -0,0 +1,17 @@ +namespace RemoveGetterSetterWithProperties +{ + public class Person + { + private string name; + private int age; + + public void SetPersonDetails(string name, int age) { + this.name = name; + this.age = age; + } + + public string GetPersonDetails() { + return $"Name: {name}, Age: {age}"; + } + } +} diff --git a/UsingProperties.cs b/UsingProperties.cs new file mode 100644 index 0000000..3eb6840 --- /dev/null +++ b/UsingProperties.cs @@ -0,0 +1,8 @@ +namespace RemoveGetterSetterWithProperties +{ + public class Person + { + public string Name { get; set; } + public int Age { get; set; } + } +}