troubleshooting Question

How to access method within the same class in C#

Avatar of crazy4s
crazy4s asked on
.NET ProgrammingC#Microsoft Development
54 Comments6 Solutions806 ViewsLast Modified:
Hi all,
How can i call other method within the same class? Because when i check through it seems like it didn't go to the toString()/toStringIndented() method after the constructor is called so is not printing out anything?

Can anyone show me how should i do so that i can call the another method and print it out?

public class CProgram
        List<Declaration> decpart = new List<Declaration>();
        List<Statement> body = new List<Statement>();

        public CProgram(List<Declaration> d, List<Statement> b)
            decpart = d;
            body = b;

        public String toString()
            return toStringIndented("");
        public String toStringIndented(String indent)
            string result = indent + "Program(\n";
            foreach(var item in decpart)
                result = result + item.toStringIndented(indent + "  ")  + ",\n";
            foreach(var item in body)
                result = result + item.toStringIndented(indent + "  ")  + ",\n";
            Console.WriteLine(result + indent + ")");
            return result  + indent + ")";

public CProgram program()
            List<Declaration> decls = declarations();
            List<Statement> stmts = statements();

            CProgram p = new CProgram(decls, stmts);
            if (error_flag == false)
                Console.WriteLine("No Syntax Error. Comgratulation!");

            return p;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 6 Answers and 54 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 6 Answers and 54 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros