Solving problem

Ccm

New member
Joined
Oct 10, 2015
Messages
2
Programming Experience
Beginner
Plz read the code below
C#:
        static void Main(string[] args)        {

            MyReader reader = new Reader();

            List<Account> list = reader.ImportAccount("aaa");
            foreach (Account acc in list)
            {
                acc.Report();
            }
            Console.ReadLine();


        }


Q1. should i use this to start in class "Reader"?
C#:
public void ImportAccount(string a)
Q2. also, how do i return the value?
 
Last edited by a moderator:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,792
Location
Sydney, Australia
Programming Experience
10+
Your first question makes no sense at all I'm afraid.

As for the second question, a method declared as type `void` doesn't return a value. If you want to return a value then you replace `void` with the type of the value you want to return and then use a `return` statement within the method to return the value.
 

Ccm

New member
Joined
Oct 10, 2015
Messages
2
Programming Experience
Beginner
i had to return strings to build the list. what should i use instead of void? i tried to use string but it shows an error msg "cannot implicitly convert type 'string' to System.Collections.Generic.List<XYZ.Account>"
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,792
Location
Sydney, Australia
Programming Experience
10+
i had to return strings to build the list. what should i use instead of void? i tried to use string but it shows an error msg "cannot implicitly convert type 'string' to System.Collections.Generic.List<XYZ.Account>"

This seems to have nothing to do with your actual question. If you method is returning a String then it's return type needs to be String. If you call the method, it will then return a String. You can then only use the return value as a String because that's what it is. You can't use it as a List<XYZ.Account> because it isn't a List<XYZ.Account>. That's like going to a machine that dispenses cans of Coke and then expecting to get into the can and drive it. If the machine gives you a can of Coke then treat it as a can of Coke because that's what it is. Likewise, if a method gives you a String then treat it as a String because that's what it is.

Think about what you're actually doing. What do you want this method to return? Do you want it to return a String or do you want it to return a List<XYZ.Account>? Whichever it is, write your method to do that and then use the return value appropriately. If you're still sure what to do then you might try providing a bit more relevant information, like what you're actually trying to achieve.
 
Top Bottom