C
C#2y ago
0_00

How to check if two values are in the same child of a class?

The user inputs their username and then their password. I want to check to see if both inputs are in the same child of the class.
13 Replies
mtreit
mtreit2y ago
What do you mean by child?
0_00
0_00OP2y ago
my bad i meant like the object made from my class so the object would include their username and password
mtreit
mtreit2y ago
You might need to show some code because it's not very clear what you are asking.
0_00
0_00OP2y ago
my bad,
while(!fileReader.EndOfStream){
string lineOfData = fileReader.ReadLine()!;
string[] accountData = lineOfData.Split(",");
string accountNumber = accountData[0];
int accountPIN = int.Parse(accountData[1]);
string first_name = accountData[2];
string last_name = accountData[3];
float accountBalance = float.Parse(accountData[4]);
int totalDeposits = int.Parse(accountData[5]);
int totalWithdrawals = int.Parse(accountData[6]);
string accountType = (accountData[7]);
accountList.Add(new Account(accountNumber,accountPIN, first_name, last_name, accountBalance, totalDeposits, totalWithdrawals, accountType));
while(!fileReader.EndOfStream){
string lineOfData = fileReader.ReadLine()!;
string[] accountData = lineOfData.Split(",");
string accountNumber = accountData[0];
int accountPIN = int.Parse(accountData[1]);
string first_name = accountData[2];
string last_name = accountData[3];
float accountBalance = float.Parse(accountData[4]);
int totalDeposits = int.Parse(accountData[5]);
int totalWithdrawals = int.Parse(accountData[6]);
string accountType = (accountData[7]);
accountList.Add(new Account(accountNumber,accountPIN, first_name, last_name, accountBalance, totalDeposits, totalWithdrawals, accountType));
is how im making my objects
class Account{
private string first_name, last_name, accountType, accountNumber;
private int accountPIN, totalDeposits, totalWithdrawals;

private float accountBalance;


public Account (string accountNumber, int accountPIN, string first_name, string last_name, float accountBalance, int totalDeposits, int totalWithdrawals, string accountType){
this.accountNumber = accountNumber;
this.accountPIN = accountPIN;
this.first_name = first_name;
this.last_name = last_name;
this.accountBalance = accountBalance;
this.totalDeposits = totalDeposits;
this.totalWithdrawals = totalWithdrawals;
this.accountType = accountType;
}
///Get and set for class
public string getaccountNumber(){
return this.accountNumber;
}
public void setaccountNumber(string newaccountNumber){
this.accountNumber = newaccountNumber;
}
public int getaccountPIN(){
return this.accountPIN;
}
public void setaccountPIN(int newaccountPIN){
this.accountPIN= newaccountPIN;
}
public string getfirst_name(){
return this.first_name;
}
public void setfirst_name(string newfirst_name){
this.first_name = newfirst_name;
}
public string getlast_name(){
return this.last_name;
}
public void setlast_name(string newlast_name){
this.last_name = newlast_name;
}
public float getaccountBalance(){
return this.accountBalance;
}
public void setaccountBalance(float newaccountBalance){
this.accountBalance = newaccountBalance;
}
public int gettotalDeposits(){
return this.totalDeposits;
}
public void settotalDeposits(int newTotalDeposits){
this.totalDeposits = newTotalDeposits;
}
public int gettotalWithdrawals(){
return this.totalWithdrawals;
}
public void settotalWithdrwals(int newTotalWithdrawals){
this.totalWithdrawals = newTotalWithdrawals;
}
public string getaccountType(){
return this.accountType;
}
public void setaccountType(string newaccountType){
this.accountType = newaccountType;
}
///get and set ended
///methods begin now

}
class Account{
private string first_name, last_name, accountType, accountNumber;
private int accountPIN, totalDeposits, totalWithdrawals;

private float accountBalance;


public Account (string accountNumber, int accountPIN, string first_name, string last_name, float accountBalance, int totalDeposits, int totalWithdrawals, string accountType){
this.accountNumber = accountNumber;
this.accountPIN = accountPIN;
this.first_name = first_name;
this.last_name = last_name;
this.accountBalance = accountBalance;
this.totalDeposits = totalDeposits;
this.totalWithdrawals = totalWithdrawals;
this.accountType = accountType;
}
///Get and set for class
public string getaccountNumber(){
return this.accountNumber;
}
public void setaccountNumber(string newaccountNumber){
this.accountNumber = newaccountNumber;
}
public int getaccountPIN(){
return this.accountPIN;
}
public void setaccountPIN(int newaccountPIN){
this.accountPIN= newaccountPIN;
}
public string getfirst_name(){
return this.first_name;
}
public void setfirst_name(string newfirst_name){
this.first_name = newfirst_name;
}
public string getlast_name(){
return this.last_name;
}
public void setlast_name(string newlast_name){
this.last_name = newlast_name;
}
public float getaccountBalance(){
return this.accountBalance;
}
public void setaccountBalance(float newaccountBalance){
this.accountBalance = newaccountBalance;
}
public int gettotalDeposits(){
return this.totalDeposits;
}
public void settotalDeposits(int newTotalDeposits){
this.totalDeposits = newTotalDeposits;
}
public int gettotalWithdrawals(){
return this.totalWithdrawals;
}
public void settotalWithdrwals(int newTotalWithdrawals){
this.totalWithdrawals = newTotalWithdrawals;
}
public string getaccountType(){
return this.accountType;
}
public void setaccountType(string newaccountType){
this.accountType = newaccountType;
}
///get and set ended
///methods begin now

}
is how my class is set up so basically what im trying to check is if the accountnumber that the user inputs contains a matching pin in one of the objects I have made
Angius
Angius2y ago
Well, check that, then userInput.Contains(someAccount.Pin) (as a side note, most of your code is useless Java-isms, C# has autoproperties, no need to waste time writing getter and setter methods)
0_00
0_00OP2y ago
ohh ok nice ill fix that in a few so I'm in the process of doing that right now but whenever I try to access my objects I get the output of
0_00
0_00OP2y ago
Angius
Angius2y ago
How are you accessing them and how are you getting the output?
0_00
0_00OP2y ago
foreach(Account account in accountList){
Console.WriteLine(account);
}
foreach(Account account in accountList){
Console.WriteLine(account);
}
Angius
Angius2y ago
Well, your account doesn't override the ToString() method so you'll just get the class name If you want to print all properties of the object, you can try serializing it to JSON
foreach (var account in accounts)
{
Console.WriteLine(JsonSerializer.Serialize(account));
}
foreach (var account in accounts)
{
Console.WriteLine(JsonSerializer.Serialize(account));
}
or some such
0_00
0_00OP2y ago
okok that makes sense Im trying to make the login right now and when I do
if(currentaccountNumber.Contains(accountNumber) && currentPIN1.Contains(accountPIN));
if(currentaccountNumber.Contains(accountNumber) && currentPIN1.Contains(accountPIN));
it tells me that accountNumber and accountPIN dont exist in the current context currentaccountNumber and currentPIN1 are the user input
Angius
Angius2y ago
Well, do they exist? $scopes
MODiX
MODiX2y ago
scope A {
thing a;
scope B {
thing b;
}
}
scope A {
thing a;
scope B {
thing b;
}
}
thing a is available in scope A and scope B thing b is available only in scope B
Want results from more Discord servers?
Add your server