C
C#2y ago
DayKnight

✅ Accsessing Method in another class by object

I have a customer class which contains the method I want to access
public override void GetAllVichles(List<Enrollment> en)
{
//en.Sort();
foreach (var enrollment in en)
{
foreach (var item in enrollment.Enrollments)
{
if (item.CustomerInfo.FirstName == FirstName && item.CustomerInfo.LastName == LastName)
{
Console.WriteLine($"{item.CustomerInfo.FirstName} {item.VichleInfo.vichleList}");
};
}
}
}
public override void GetAllVichles(List<Enrollment> en)
{
//en.Sort();
foreach (var enrollment in en)
{
foreach (var item in enrollment.Enrollments)
{
if (item.CustomerInfo.FirstName == FirstName && item.CustomerInfo.LastName == LastName)
{
Console.WriteLine($"{item.CustomerInfo.FirstName} {item.VichleInfo.vichleList}");
};
}
}
}
I want to call that method in my program.cs inside my foreach
Console.WriteLine("Write name of customer");
string customSearch = Console.ReadLine();
foreach (var item in vichle.vichleList)
{
if(customSearch == item.Owner.FirstName)
{

}
Console.WriteLine("Write name of customer");
string customSearch = Console.ReadLine();
foreach (var item in vichle.vichleList)
{
if(customSearch == item.Owner.FirstName)
{

}
It is supposed to search for customers with the written name Thanks beforehand 🙂
7 Replies
Angius
Angius2y ago
item.GetAllVichles() probably
hiyosilver
hiyosilver2y ago
wth is a vichle...? Hmm
DayKnight
DayKnight2y ago
Angius
Angius2y ago
Well, what class is GetAllVichles() a method of? Because you'll need an instance of that class
atakancracker
atakancracker2y ago
Base of Vehicle
DayKnight
DayKnight2y ago
Oof, you are right. I am making no instance for the class
item.Owner.GetAllVichles();
item.Owner.GetAllVichles();
This is what I had to do
Accord
Accord2y ago
Closed!
Want results from more Discord servers?
Add your server
More Posts