© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
8 replies
SimplyKazuki

✅ 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
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 🙂
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ accessing object from a class inside of another class
C#CC# / help
3y ago
❔ Can separate class objects contain instances of the same method object
C#CC# / help
3y ago
❔ Using method in other class
C#CC# / help
3y ago