简体   繁体   中英

Trouble with assigning/calling methods from another class C#

I've looked through other questions but I can't understand what's going on in the answer so I'll post my code here:

public class Program
{
    public static void Main()
    {
        Program startUp = new Program();
        Console.Clear();


        string file = @FILEPATH
        string grades = File.ReadAllText(file);                                                                                  
        int acount = grades.Count(c => c == 'A');
        startUp.Grapher();

    }


    public class Graph
    {
        public static string Grapher(int acount)
        {
         Console.WriteLine(String.Concat(Enumerable.Repeat("*", acount))); Console.Write(": A");

}}

Any help or explanation would be fantastic!

ok, from what i see you create a Program class instance and then try to use a Graph class method.

you should use Graph class instance.

public static void Main()
{
    Console.Clear();

    string file = @FILEPATH
    string grades = File.ReadAllText(file);                                                                                  
    int acount = grades.Count(c => c == 'A');
    Graph.Grapher(acount);// this is the change

}

and the Graph class will be:

public class Graph
{
    public static void Grapher(int acount)// the change is here
    {
       Console.WriteLine(String.Concat(Enumerable.Repeat("*", acount))); Console.Write(": A");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM