How to define and use private method in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    public class Example
    {
        int n = 3; 

        public void Show()
        {
            Console.WriteLine(n);
        }
        private void Calc()
        {
            n = n * n * n;
        }
        public void test()
        {
            Calc();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Example e = new Example();

            e.test();

            e.Show();
        }
    }
}


/*
run:
 
27

*/

 



answered Jan 1, 2017 by avibootz

Related questions

2 answers 213 views
1 answer 206 views
1 answer 191 views
1 answer 170 views
1 answer 169 views
1 answer 159 views
...