repl.it
@kironroy/

methods

C#

method overloading, params, ref modier, out modifer

fork
loading
Files
  • main.cs
  • CalculatorTwo.cs
  • main.exe
  • notes.txt
  • Point.cs
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Methods
{

    class Program
    {
        static void Main(string[] args)
        {
            ParseAttempt();
            BreakLine();

            Console.WriteLine("Below is the params method: ");
            UseParams();

            BreakLine();


            Console.WriteLine("Below is the points method: ");
            UsePoints();

            BreakLine();

            var calculation1 = new CalculatorTwo();
           
           Console.WriteLine("Calulation of 1 + 2 + 3 = " + " " + calculation1.Add(1,3));






        }

        private static void BreakLine()
        {
            Console.WriteLine();
        }

        static void ParseAttempt()
        {
            int number;
            var result = int.TryParse("abc", out number);
            if (result)
                Console.WriteLine(number);
            else
                Console.WriteLine("Conversion failed");
        }

        static  void UseParams()
        {
            var calc = new CalculatorTwo();
            Console.WriteLine(calc.Add(1, 2));
            Console.WriteLine(calc.Add(1, 2, 3, 4));

            var point = new Point(10, 20);
            point.Move(100, 200);
            Console.WriteLine("Point is at ({0}, {1})", point.X, point.Y);
        }


        static void UsePoints()
            {
                try
                {
                    var point = new Point(10, 20);
                    point.Move(100, 200);
                    Console.WriteLine("Point is at ({0}, {1})", point.X, point.Y);

                    point.Move(100, 200);
                    Console.WriteLine("Point is at ({0}, {1})", point.X, point.Y);
                }
                catch (Exception)
                {

                    Console.WriteLine("An unexcepted error occured");
                }

            }

        
    }
}