How to define and use public methods in C#

1 Answer

0 votes
using System;

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

        public void Show()
        {
            Console.WriteLine(n);
        }
        public void Calc(int v)
        {
            n = n * v;
        }
    }

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

            e.Calc(10);

            e.Show();
        }
    }
}


/*
run:
 
30

*/

 



answered Jan 1, 2017 by avibootz

Related questions

1 answer 135 views
1 answer 104 views
104 views asked Sep 9, 2020 by avibootz
1 answer 149 views
149 views asked Aug 21, 2018 by avibootz
1 answer 155 views
155 views asked Jan 1, 2017 by avibootz
1 answer 171 views
...