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..8b7ad955 --- /dev/null +++ b/EnumsLinq/Enums/Program.cs @@ -0,0 +1,34 @@ +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))) + { + System.Console.WriteLine(item); + } + if (myBirthday == DaysWithNumbers.Friday) + { + System.Console.WriteLine(); + } + + } + 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..987cbdc9 --- /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..95c33a43 --- /dev/null +++ b/EnumsLinq/Linq/Program.cs @@ -0,0 +1,48 @@ +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 + 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; + } +} 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; } } }