Skip to content

Commit d6b9ad0

Browse files
committed
[Prolifik]
1 parent 15dc00d commit d6b9ad0

7 files changed

Lines changed: 218 additions & 1 deletion

File tree

LearningCSharp.Cmd/LearningCSharp.Cmd.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<WarningLevel>4</WarningLevel>
3333
</PropertyGroup>
3434
<PropertyGroup>
35-
<StartupObject>LearningCSharp.Cmd.Series4.LINQ.Tester</StartupObject>
35+
<StartupObject>LearningCSharp.Cmd.Series4.LINQPlus.Tester1</StartupObject>
3636
</PropertyGroup>
3737
<ItemGroup>
3838
<Reference Include="System" />
@@ -90,6 +90,8 @@
9090
<Compile Include="Series3\Delegates\Tester.cs" />
9191
<Compile Include="Series3\ExtensionPlus\Excercise.cs" />
9292
<Compile Include="Series3\ExtensionPlus\Program.cs" />
93+
<Compile Include="Series4\LINQPlus\Tester.cs" />
94+
<Compile Include="Series4\LINQPlus\Tester1.cs" />
9395
<Compile Include="Series4\LINQ\Program.cs" />
9496
<Compile Include="Series4\LINQ\Tester.cs" />
9597
<Compile Include="Types\Tester.cs" />
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using LearningCSharp.Topics.LINQ;
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.Series4.LINQPlus
9+
{
10+
public class Tester
11+
{
12+
public static void Main()
13+
{
14+
var keywords = CollectionManager.GetTechWords();
15+
var keyList = CollectionManager.KeyList;
16+
17+
Dictionary<string, string> dictionary2 =
18+
new Dictionary<string, string>();
19+
20+
dictionary2.Add("CLR", "Common Language Runtime(2)");
21+
22+
var j = keywords.Union(dictionary2);
23+
24+
foreach (var item in j)
25+
{
26+
Console.WriteLine($"{item.Key}: {item.Value}");
27+
}
28+
29+
Console.WriteLine("===============================");
30+
31+
keywords["CLR"] = "Common Language Runtime (2)";
32+
//if (!keywords.ContainsKey("CLR"))
33+
//{
34+
// keywords.Add("CLR", "Common Language Runtime");
35+
//}
36+
37+
foreach (var item in keywords)
38+
{
39+
Console.WriteLine($"{item.Key}: {item.Value}");
40+
}
41+
42+
Console.ReadLine();
43+
//IEnumerable<KeyValuePair<string, string>> a = keywords.Where(n => n.Value.Contains("a"))
44+
// .OrderBy(n => n.Value.Length)
45+
// .Select(n => n);
46+
47+
var a = from k in keywords
48+
let nk = k.Value.Replace("a", "")
49+
where nk.Length > 9
50+
select k;
51+
52+
53+
54+
}
55+
}
56+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using LearningCSharp.Topics.Domains;
2+
using LearningCSharp.Topics.LINQ;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace LearningCSharp.Cmd.Series4.LINQPlus
10+
{
11+
public class Tester1
12+
{
13+
public static void Main()
14+
{
15+
List<Category> squad = new List<Category>()
16+
{
17+
new Category(){ Name = "Jersey" },
18+
new Category(){ Name = "Boot" },
19+
};
20+
21+
var squadResult = squad.Last(s => s.Name.Contains("gaby"));
22+
Console.WriteLine(squadResult);
23+
24+
var name1 = new List<dynamic> { new { Name = "Prolifik", Id = 1 } };
25+
var name2 = new List<dynamic> { new { Name = "Lexzy", Id = 2 } };
26+
27+
var name1Name2 = from n1 in name1
28+
join n2 in name2
29+
on n1.Id equals n2.Id
30+
select new { FullName = $"{n1.Name} {n2.Name}" };
31+
32+
33+
foreach (var item in name1Name2)
34+
{
35+
Console.WriteLine(item.FullName);
36+
}
37+
38+
Console.WriteLine("======================");
39+
40+
List<string> names = new List<string>()
41+
{
42+
"Gaby",
43+
"Prolifik",
44+
"Lola"
45+
};
46+
47+
names.ForEach(n => { Console.WriteLine(n); });
48+
49+
50+
var categories = names.Select(n => new { Name = n });
51+
52+
53+
Console.WriteLine(names.Skip(2).Last());
54+
55+
var prodList = CollectionManager.GetProduct().GroupBy(p => p.Category);
56+
57+
foreach (var groupKey in prodList)
58+
{
59+
Console.Write(groupKey.Key);
60+
Console.WriteLine("======================");
61+
foreach (var item in groupKey)
62+
{
63+
Console.WriteLine($"{item.Category}: {item.Name}");
64+
}
65+
}
66+
67+
Console.Read();
68+
}
69+
}
70+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace LearningCSharp.Topics.Domains
2+
{
3+
public class Category
4+
{
5+
public string Name { get; set; }
6+
}
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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.Topics.Domains
8+
{
9+
public class Product
10+
{
11+
public int Id { get; set; }
12+
public string Name { get; set; }
13+
public string Category { get; set; }
14+
}
15+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using LearningCSharp.Topics.Domains;
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.Topics.LINQ
9+
{
10+
public class CollectionManager
11+
{
12+
13+
public static List<Product> GetProduct()
14+
{
15+
string[] categories = new string[]
16+
{
17+
"BEVERAGES",
18+
"DETERGENT",
19+
};
20+
21+
List<Product> productList = new List<Product>();
22+
productList.Add(new Product()
23+
{
24+
Category = categories.First(),
25+
Id = 1,
26+
Name = "Milo"
27+
});
28+
productList.Add(new Product()
29+
{
30+
Category = categories.Last(),
31+
Id = 2,
32+
Name = "Good mama"
33+
});
34+
productList.Add(new Product()
35+
{
36+
Category = categories.First(),
37+
Id = 3,
38+
Name = "Milk shake"
39+
});
40+
41+
42+
return productList;
43+
44+
}
45+
public static List<KeyValuePair<string, string>> KeyList { get; set; } = new List<KeyValuePair<string, string>>();
46+
47+
public static Dictionary<string, string> GetTechWords()
48+
{
49+
50+
Dictionary<string, string> dictionary =
51+
new Dictionary<string, string>
52+
{
53+
{ "CLR", "Common Language Runtime" },
54+
{ "CTS", "Common Type System"},
55+
{ "CLI", "Common Language Infrstructure"}
56+
};
57+
58+
59+
KeyList = dictionary.ToList();
60+
KeyValuePair<string, string>[] v = dictionary.ToArray();
61+
return dictionary;
62+
}
63+
}
64+
}

LearningCSharp.Topics/LearningCSharp.Topics.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
</ItemGroup>
4242
<ItemGroup>
4343
<Compile Include="Delegates\Shape.cs" />
44+
<Compile Include="Domains\Category.cs" />
45+
<Compile Include="Domains\Product.cs" />
4446
<Compile Include="Enumeration\People.cs" />
47+
<Compile Include="LINQ\CollectionManager.cs" />
4548
<Compile Include="Properties\AssemblyInfo.cs" />
4649
<Compile Include="TryException\MyCustomEx.cs" />
4750
</ItemGroup>

0 commit comments

Comments
 (0)