From da409d8b3ae63a9cb6583663ceba5fc376b7eb32 Mon Sep 17 00:00:00 2001 From: Sam Mangum-Bostick Date: Wed, 27 Feb 2019 18:33:33 -0600 Subject: [PATCH 1/2] progress --- EnumsLinq/Enums/Enums.csproj | 8 +++++ EnumsLinq/Enums/Program.cs | 30 ++++++++++++++++ EnumsLinq/EnumsPractice/EnumsPractice.csproj | 8 +++++ EnumsLinq/EnumsPractice/Program.cs | 32 +++++++++++++++++ EnumsLinq/Linq/Linq.csproj | 8 +++++ EnumsLinq/Linq/Program.cs | 38 ++++++++++++++++++++ Linq/Linq.cs | 15 +++++++- 7 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 EnumsLinq/Enums/Enums.csproj create mode 100644 EnumsLinq/Enums/Program.cs create mode 100644 EnumsLinq/EnumsPractice/EnumsPractice.csproj create mode 100644 EnumsLinq/EnumsPractice/Program.cs create mode 100644 EnumsLinq/Linq/Linq.csproj create mode 100644 EnumsLinq/Linq/Program.cs diff --git a/EnumsLinq/Enums/Enums.csproj b/EnumsLinq/Enums/Enums.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/EnumsLinq/Enums/Enums.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/EnumsLinq/Enums/Program.cs b/EnumsLinq/Enums/Program.cs new file mode 100644 index 00000000..e8d4d0fe --- /dev/null +++ b/EnumsLinq/Enums/Program.cs @@ -0,0 +1,30 @@ +using System; + +namespace Enums +{ + class Program + { + static void Main(string[] args) + { + DaysWithNumbers myBirthday = DaysWithNumbers.Friday; + Console.WriteLine("Hello World!"); + // foreach (var item in Enum.GetValues(typeof(Days))) + // { + // System.Console.WriteLine(item); + // } + // foreach (var item in Enum.GetValues(typeof(DaysWithNumbers))) + // { + + // } + + } + enum Days + { + Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday + } + enum DaysWithNumbers + { + Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6, Sunday = 7 + } + } +} diff --git a/EnumsLinq/EnumsPractice/EnumsPractice.csproj b/EnumsLinq/EnumsPractice/EnumsPractice.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/EnumsLinq/EnumsPractice/EnumsPractice.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/EnumsLinq/EnumsPractice/Program.cs b/EnumsLinq/EnumsPractice/Program.cs new file mode 100644 index 00000000..361c46a8 --- /dev/null +++ b/EnumsLinq/EnumsPractice/Program.cs @@ -0,0 +1,32 @@ +using System; + +namespace EnumsPractice +{ + class Program + { + static void Main(string[] args) + { + // Console.WriteLine("Hello World!"); + // foreach (var item in Enum.GetValues(typeof(Months))) + // { + // System.Console.WriteLine(item); + // } + } + // enum Months + // { + // January, February, March, April, May, June, July, August, September, October, November, December + // } + Point point1 = new Point(0, 1); + Point point2 = new Point(2, 2); + public struct Point + { + public int X { get; set; } + public int Y { get; set; } + public Point(int x, int y) + { + this.X = x; + this.Y = y; + } + } + } +} diff --git a/EnumsLinq/Linq/Linq.csproj b/EnumsLinq/Linq/Linq.csproj new file mode 100644 index 00000000..21dff5ca --- /dev/null +++ b/EnumsLinq/Linq/Linq.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.2 + + + diff --git a/EnumsLinq/Linq/Program.cs b/EnumsLinq/Linq/Program.cs new file mode 100644 index 00000000..20193b75 --- /dev/null +++ b/EnumsLinq/Linq/Program.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StudentList +{ + public class Program + { + public static void Main() + { + List students = new List(); + + students.Add(new Student("Chris", "123-456-7891", "123 Delany", -2990)); + students.Add(new Student("Kevin", "512-222-2222", "435 Carolyn", -2500)); + students.Add(new Student("Victoria", "512-827-8498", "701 Brazos St", 0)); + students.Add(new Student("Luke", "555-555-5555", "451 Brody Ln", -500)); + + //your code here + } + + } + + public class Student + { + public string Name { get; set; } + public string Phone { get; set; } + public string Address { get; set; } + public int Balance { get; set; } + + public Student(string name, string phone, string address, int balance) + { + Name = name; + Phone = phone; + Address = address; + Balance = balance; + } + } +} \ No newline at end of file diff --git a/Linq/Linq.cs b/Linq/Linq.cs index 6cabb44e..3a8263db 100644 --- a/Linq/Linq.cs +++ b/Linq/Linq.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; namespace Linq { @@ -6,7 +7,19 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + + var source = new int[] { 1, 2 }; + var results = + from i in source + select i; + + int total = source.Where(x => true).Select(Square).Sum(); + Console.WriteLine(total); + + } + public static int Square(int value) + { + return value * value; } } } From aaadecb861c1c1a29565d544bce55c3b57c33295 Mon Sep 17 00:00:00 2001 From: Sam Mangum-Bostick Date: Mon, 4 Mar 2019 13:30:58 -0600 Subject: [PATCH 2/2] Completed Enums and Linq --- EnumsLinq/Enums/Program.cs | 12 ++++++--- EnumsLinq/EnumsPractice/Program.cs | 18 +++++++------- EnumsLinq/Linq/Program.cs | 40 +++++++++++++++++++----------- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/EnumsLinq/Enums/Program.cs b/EnumsLinq/Enums/Program.cs index e8d4d0fe..8b7ad955 100644 --- a/EnumsLinq/Enums/Program.cs +++ b/EnumsLinq/Enums/Program.cs @@ -12,10 +12,14 @@ static void Main(string[] args) // { // System.Console.WriteLine(item); // } - // foreach (var item in Enum.GetValues(typeof(DaysWithNumbers))) - // { - - // } + foreach (var item in Enum.GetValues(typeof(DaysWithNumbers))) + { + System.Console.WriteLine(item); + } + if (myBirthday == DaysWithNumbers.Friday) + { + System.Console.WriteLine(); + } } enum Days diff --git a/EnumsLinq/EnumsPractice/Program.cs b/EnumsLinq/EnumsPractice/Program.cs index 361c46a8..987cbdc9 100644 --- a/EnumsLinq/EnumsPractice/Program.cs +++ b/EnumsLinq/EnumsPractice/Program.cs @@ -6,16 +6,16 @@ class Program { static void Main(string[] args) { - // Console.WriteLine("Hello World!"); - // foreach (var item in Enum.GetValues(typeof(Months))) - // { - // System.Console.WriteLine(item); - // } + Console.WriteLine("Hello World!"); + foreach (var item in Enum.GetValues(typeof(Months))) + { + System.Console.WriteLine(item); + } + } + enum Months + { + January, February, March, April, May, June, July, August, September, October, November, December } - // enum Months - // { - // January, February, March, April, May, June, July, August, September, October, November, December - // } Point point1 = new Point(0, 1); Point point2 = new Point(2, 2); public struct Point diff --git a/EnumsLinq/Linq/Program.cs b/EnumsLinq/Linq/Program.cs index 20193b75..95c33a43 100644 --- a/EnumsLinq/Linq/Program.cs +++ b/EnumsLinq/Linq/Program.cs @@ -16,23 +16,33 @@ public static void Main() students.Add(new Student("Luke", "555-555-5555", "451 Brody Ln", -500)); //your code here - } + IEnumerable negativeBalance = from currentStudent in students + where currentStudent.Balance < 0 + select currentStudent; + + Console.WriteLine("Students with a negative balance:"); + foreach (Student currentStudent in negativeBalance) + { + Console.WriteLine(currentStudent.Name); + } + } } - public class Student - { - public string Name { get; set; } - public string Phone { get; set; } - public string Address { get; set; } - public int Balance { get; set; } +} - public Student(string name, string phone, string address, int balance) - { - Name = name; - Phone = phone; - Address = address; - Balance = balance; - } +public class Student +{ + public string Name { get; set; } + public string Phone { get; set; } + public string Address { get; set; } + public int Balance { get; set; } + + public Student(string name, string phone, string address, int balance) + { + Name = name; + Phone = phone; + Address = address; + Balance = balance; } -} \ No newline at end of file +}