Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- // init first object of class User
- User first = new User();
- first.setData("user1", "123123");
- first.getData();
- first.age = 27;
- // init second object of class User
- User second = new User();
- second.setData("user2", "444444");
- second.getData();
- second.age = 19;
- second.compareWith(first);
- Console.ReadKey();
- }
- }
- class User
- {
- // properties
- string username;
- string password;
- string email;
- public int age;
- // constructor
- /*
- public User(string nUsername, string nPassword)
- {
- username = nUsername;
- password = nPassword;
- }
- */
- // functions
- public void setData(string nUsername, string nPassword)
- {
- username = nUsername;
- password = nPassword;
- }
- public void getData()
- {
- Console.WriteLine("User details u: " + username + " p: " + password);
- }
- public void tryLogin()
- {
- Console.WriteLine("enter username:");
- string tryUsername = Console.ReadLine();
- Console.WriteLine("enter password:");
- string tryPassword = Console.ReadLine();
- if(password == tryPassword && username == tryUsername)
- {
- Console.WriteLine("Success!");
- } else
- {
- Console.WriteLine("Error!");
- }
- }
- public void compareWith(User other)
- {
- if (this.age > other.age)
- {
- Console.WriteLine(this.username + " is older than " + other.username);
- }
- else if (this.age < other.age)
- {
- Console.WriteLine(other.username + " is older than " + this.username);
- }
- else
- {
- Console.WriteLine(this.username + " and " + other.username + " are the same age.");
- }
- }
- }
- }
- // https://pastebin.com/3GdLbwJj
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement