-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (49 loc) · 1.47 KB
/
Copy pathProgram.cs
File metadata and controls
57 lines (49 loc) · 1.47 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MethodExample
{
class MethodExample
{
int number;
public void SomeMethod(int newValue)
{
this.number = newValue;
}
public void AnotherMethod()
{
Console.WriteLine(this.number);
}
//public int Add(int x)
// {
// return x + this.number;
// }
public int Add(int x) => x + this.number;
public void OptionalArgumentMethod(int x = 10, string y = "Hello")
{
Console.WriteLine($"{x} {y} {this.number}");
}
public void ParamsMethod(string required, params string[] extras)
{
if (extras == null)
throw new ArgumentNullException(nameof(extras));
Console.WriteLine(required);
foreach (var extra in extras)
Console.WriteLine(extra);
}
static void Main()
{
var example = new MethodExample();
example.OptionalArgumentMethod();
example.OptionalArgumentMethod(12);
example.OptionalArgumentMethod(y: "Goodbye");
example.ParamsMethod("required","one","two");
example.ParamsMethod("required");
example.ParamsMethod("required", new string[] { "one", "two" });
example.ParamsMethod("required");
example.ParamsMethod("required", null);
}
}
}