C
C#2y ago
Sam DZ

✅ how to move it to abstract class

I want to move admin user name & adminpass to abstract class or method The point is how to compare them to user input after that
15 Replies
Becquerel
Becquerel2y ago
Why do you want to make it abstract?
Sam DZ
Sam DZOP2y ago
Just because the Dr. In college want that lol 💔 @Becquerel
Becquerel
Becquerel2y ago
PepeHands professors the way you would do it is like this
public abstract class Login
{
void Login();
}

public class AdminLogin : Login
{
public void override Login()
{
// same as what you already have, including user input
}
}

public class UserLogin : Login
{
public void override Login()
{
// you can do this differently than in the AdminLogin class, assuming that users login differently to admins
}
}
public abstract class Login
{
void Login();
}

public class AdminLogin : Login
{
public void override Login()
{
// same as what you already have, including user input
}
}

public class UserLogin : Login
{
public void override Login()
{
// you can do this differently than in the AdminLogin class, assuming that users login differently to admins
}
}
this lets you do this:
var logins = new List<Login>();

// We can treat both classes as if they were the same and put them in the same list.
logins.Add(new AdminLogin());
logins.Add(new UserLogin());

// Because we can treat both classes as if they are the same, we can call the methods common to both of them - the methods in the abstract class
foreach (var login in logins)
{
login.Login();
}
var logins = new List<Login>();

// We can treat both classes as if they were the same and put them in the same list.
logins.Add(new AdminLogin());
logins.Add(new UserLogin());

// Because we can treat both classes as if they are the same, we can call the methods common to both of them - the methods in the abstract class
foreach (var login in logins)
{
login.Login();
}
mtreit
mtreit2y ago
As an aside, let's talk about using a string to control your loop...
Sam DZ
Sam DZOP2y ago
@mtreit What you want to talk about it? @Becquerel
I'm going to try it
mtreit
mtreit2y ago
Use a boolean value directly
Sam DZ
Sam DZOP2y ago
I found this easier You can call me Baby junior 😂😎 @mtreit
mtreit
mtreit2y ago
Yes?
Sam DZ
Sam DZOP2y ago
Any content creator or book recommendations for be better in c# i will appreciate it 🙌🏻 @mtreit
mtreit
mtreit2y ago
Have you done $helloworld ?
Sam DZ
Sam DZOP2y ago
@mtreit I'm doing my first oop for college So i get a step forward in base ideas
mtreit
mtreit2y ago
The interactive course I linked is a good place to start to get familiar with C# as a language
Sam DZ
Sam DZOP2y ago
@Becquerel I didn't know how to do it It gives me many errors
Becquerel
Becquerel2y ago
i don't know what those errors are
Want results from more Discord servers?
Add your server