Skip to content

Commit 5db2870

Browse files
committed
[Prolifik] params keyword
1 parent 2df94a2 commit 5db2870

15 files changed

Lines changed: 522 additions & 2 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using LearningCSharp.Cmd.Excercise2.try1;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using d = LearningCSharp.Cmd.Excercise2.try2;
8+
9+
namespace LearningCSharp.Cmd.Excercise2
10+
{
11+
public class Tester
12+
{
13+
public static void Main()
14+
{
15+
// Excercise 2
16+
17+
d.Dog dogA = new d.Dog { Name = "Tupac" };
18+
d.Dog dogB = new d.Dog { Name = "Tupac" };
19+
20+
if (dogA == dogB)
21+
{
22+
Console.WriteLine("Dogs are equal");
23+
}
24+
else
25+
{
26+
Console.WriteLine("Dogs are not equal");
27+
}
28+
29+
30+
Console.Read();
31+
32+
// Excercise 1
33+
List<Animal> animals = new List<Animal>()
34+
{
35+
new Dog(4.5, "Lucy"),
36+
new Cat(4.5, "Mooreen"),
37+
new Dog(4.5, "Charlie"),
38+
new Cat(4.5, "Luke"),
39+
new Dog(4.5, "James"),
40+
};
41+
42+
43+
foreach (Animal item in animals)
44+
{
45+
item.Move();
46+
item.Speak();
47+
item.ToString();
48+
49+
}
50+
51+
Console.Read();
52+
}
53+
}
54+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace LearningCSharp.Cmd.Excercise2.try1
8+
{
9+
public abstract class Animal
10+
{
11+
private double _weight;
12+
private string _name;
13+
public Animal(double weight, string name)
14+
{
15+
_weight = weight;
16+
_name = name;
17+
}
18+
19+
public abstract void Speak();
20+
public abstract void Move();
21+
public new abstract void ToString();
22+
}
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace LearningCSharp.Cmd.Excercise2.try1
8+
{
9+
public class Cat : Animal
10+
{
11+
public Cat(double weight, string name) : base(weight, name)
12+
{
13+
14+
}
15+
public override void Move()
16+
{
17+
Console.WriteLine($"{nameof(Cat)} Move");
18+
}
19+
20+
public override void Speak()
21+
{
22+
Console.WriteLine($"{nameof(Cat)} Move");
23+
}
24+
25+
public override void ToString()
26+
{
27+
Console.WriteLine($"{nameof(Cat)} ToString()");
28+
}
29+
}
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace LearningCSharp.Cmd.Excercise2.try1
8+
{
9+
public class Dog: Animal
10+
{
11+
public Dog(double weight, string name) : base(weight, name)
12+
{
13+
14+
}
15+
16+
public override void Move()
17+
{
18+
Console.WriteLine($"{nameof(Dog)} Move");
19+
}
20+
21+
public override void Speak()
22+
{
23+
Console.WriteLine($"{nameof(Dog)} Speak");
24+
}
25+
26+
public override void ToString()
27+
{
28+
Console.WriteLine($"{nameof(Dog)} ToString");
29+
}
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace LearningCSharp.Cmd.Excercise2.try2
8+
{
9+
public class Dog
10+
{
11+
public string Name { get; set; }
12+
13+
14+
public static bool operator ==(Dog a, Dog b)
15+
{
16+
return a.Equals(b);
17+
}
18+
public static bool operator !=(Dog a, Dog b)
19+
{
20+
return a.Equals(b);
21+
22+
}
23+
public override bool Equals(object obj)
24+
{
25+
var d = obj as Dog;
26+
27+
if (d is Dog && d.Name == this.Name)
28+
{
29+
return true;
30+
}
31+
return false;
32+
}
33+
}
34+
}

LearningCSharp.Cmd/LearningCSharp.Cmd.csproj

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<WarningLevel>4</WarningLevel>
3333
</PropertyGroup>
3434
<PropertyGroup>
35-
<StartupObject>LearningCSharp.Cmd.Series3.Delegates.Tester</StartupObject>
35+
<StartupObject>LearningCSharp.Cmd.Series3.Enumeration.Tester</StartupObject>
3636
</PropertyGroup>
3737
<ItemGroup>
3838
<Reference Include="System" />
@@ -47,6 +47,11 @@
4747
<Reference Include="System.Xml" />
4848
</ItemGroup>
4949
<ItemGroup>
50+
<Compile Include="Excercise2\Tester.cs" />
51+
<Compile Include="Excercise2\try1\Animal.cs" />
52+
<Compile Include="Excercise2\try1\Cat.cs" />
53+
<Compile Include="Excercise2\try1\Dog.cs" />
54+
<Compile Include="Excercise2\try2\Dog.cs" />
5055
<Compile Include="Properties\AssemblyInfo.cs" />
5156
<Compile Include="Series2\AnotherType.cs" />
5257
<Compile Include="Series2\Classes.cs" />
@@ -79,14 +84,22 @@
7984
<Compile Include="Series2\OOP\Vehicle.cs" />
8085
<Compile Include="Series2\Product.cs" />
8186
<Compile Include="Series2\Tester.cs" />
87+
<Compile Include="Series3\DelegateEx\Tester.cs" />
8288
<Compile Include="Series3\Delegates\ProductManager.cs" />
8389
<Compile Include="Series3\Delegates\StaffManager.cs" />
8490
<Compile Include="Series3\Delegates\Tester.cs" />
91+
<Compile Include="Series3\Enumeration\Tester.cs" />
92+
<Compile Include="Series3\TryException\Tester.cs" />
8593
<Compile Include="Types\Tester.cs" />
8694
</ItemGroup>
8795
<ItemGroup>
8896
<None Include="App.config" />
8997
</ItemGroup>
90-
<ItemGroup />
98+
<ItemGroup>
99+
<ProjectReference Include="..\LearningCSharp.Topics\LearningCSharp.Topics.csproj">
100+
<Project>{e9abd1a5-57e9-428d-a37d-b251959335ad}</Project>
101+
<Name>LearningCSharp.Topics</Name>
102+
</ProjectReference>
103+
</ItemGroup>
91104
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
92105
</Project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using LearningCSharp.Topics.Delegates;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Collections.ObjectModel;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Linq.Expressions;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace LearningCSharp.Cmd.Series3.DelegateEx
12+
{
13+
public class Tester
14+
{
15+
public static void Main()
16+
{
17+
Draw<Char, int> d = (x) => { return 9; };
18+
//d('i', new Line());
19+
20+
Func<int, int, int> predicate = delegate (int i, int j)
21+
{
22+
return '\0';
23+
};
24+
25+
26+
List<String> names = new List<string>()
27+
{
28+
"Prolifik Lexzy",
29+
"Bill Gates"
30+
};
31+
32+
var v = 2m;
33+
var result = 0m;
34+
35+
Func<decimal, decimal, decimal> action = (decimal x, decimal y) =>
36+
{
37+
result = (x * v);
38+
return result;
39+
};
40+
41+
List<Draw> drawList = new List<Draw>();
42+
int count = 0;
43+
Draw d1 = () => Console.WriteLine($"Delegate {++count}");
44+
Draw d2 = () => Console.WriteLine($"Delegate {++count}");
45+
Draw d3 = () => Console.WriteLine($"Delegate {++count}");
46+
47+
drawList.Add(d1);
48+
drawList.Add(d2);
49+
drawList.Add(d3);
50+
51+
foreach (var allDs in drawList)
52+
{
53+
allDs();
54+
}
55+
56+
List<Byte> byteList = new List<byte>();
57+
58+
FileStream stream = new FileStream("", FileMode.Create);
59+
Byte[] bytes = byteList.ToArray();
60+
61+
62+
Console.WriteLine("End of Main");
63+
Console.Read();
64+
65+
}
66+
67+
68+
public static void SomeMethod(Func<decimal, decimal, decimal> param1)
69+
{
70+
71+
Console.WriteLine($"{param1(2, 2)}");
72+
}
73+
}
74+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using LearningCSharp.Topics.Enumeration;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace LearningCSharp.Cmd.Series3.Enumeration
9+
{
10+
public class Tester
11+
{
12+
public static void Main()
13+
{
14+
//var numberList = new int[6]
15+
//{
16+
// 1,2, 6, 58, 3, 300
17+
//};
18+
//AddSet(1, 2, 6, 58, 3, 300);
19+
loop:
20+
var inputs = Console.ReadLine();
21+
22+
var numbers = inputs.Split(',', ' ' ,'\0');
23+
24+
var nums = new int[numbers.Length];
25+
26+
for (int i = 0; i < nums.Length; i++)
27+
{
28+
var s = numbers[i];
29+
30+
int r = 0;
31+
if (int.TryParse(s, out r))
32+
{
33+
nums[i] = r;
34+
}
35+
}
36+
37+
var answer = Add(nums);
38+
Console.WriteLine(answer);
39+
40+
goto loop;
41+
42+
Console.Read();
43+
}
44+
45+
static List<int> Numbers { get; set; } = new List<int>();
46+
public static void AddSet(params int[] numbers)
47+
{
48+
Numbers.AddRange(numbers);
49+
}
50+
51+
public static int Add(int x, int y)
52+
{
53+
return x + y;
54+
}
55+
56+
public static int Add(params int [] numbers)
57+
{
58+
int result = 0;
59+
60+
foreach (var num in numbers)
61+
{
62+
result = result + num;
63+
}
64+
65+
return result;
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)