Example #1
0
File: This.cs Project: rikrd92/Blog
 static void Main(string[] args)
 {
     var emp = new Employee(1, "Prasad");
     emp.PrintEmployee();
     Console.WriteLine(emp.PrintNameAndLength());
     Console.ReadLine();
 }
Example #2
0
        static void Main()
        {
            // Value Type
            Console.WriteLine("10 == 10 ? " + (10 == 10)); // returns true
            Console.WriteLine("10 != 10 ? " + (10 != 10)); // returns false.
            Console.WriteLine("10 != 20 ? " + (10 != 20)); // returns true. 

            // Reference Type
            var emp1 = new Employee();
            var emp2 = new Employee();
            Console.WriteLine("emp1 == emp2 ? " + (emp1 == emp2)); // returns false

            emp1 = emp2;
            Console.WriteLine("emp1 == emp2 ? " + (emp1 == emp2));


            // Strings
            Console.WriteLine("A == B ? " + ("A" == "B"));
            var temp = string.Copy("A");
            Console.WriteLine("A == A ? " + ("A" == temp));

            Console.ReadLine();
        }
Example #3
0
        private static void DisplayEmployee(Employee employee)
        {
            WriteLine("Employee Details");
            WriteLine("----------------");
            WriteLine();

            //WriteLine("First Name: " + employee.FirstName + " Employee Code: " + employee.EmployeeCode);
            //string line = string.Format("First Name: {0} Employee Code: {1}",
            //                            employee.FirstName,
            //                            employee.EmployeeCode);
            //WriteLine(line);

            //WriteLine("First Name: {0} Employee Code: {1}", employee.FirstName, employee.EmployeeCode);

            //line = $"First Name: {employee.FirstName} Employee Code: {employee.EmployeeCode}";
            //WriteLine(line);

            WriteLine($"First Name: {employee.FirstName} Employee Code: {employee.EmployeeCode}");

            string theHarderWay = "First Name: " + employee.FirstName.PadRight(20) +
                                  " Employee Code: " + employee.EmployeeCode.ToString().PadRight(5);

            WriteLine(theHarderWay);

            string easier = string.Format("First Name: {0,-20} Employee Code: {1,-5}",
                                          employee.FirstName,
                                          employee.EmployeeCode);

            WriteLine(easier);

            WriteLine($"First Name: {employee.FirstName,-20} Employee Code: {employee.EmployeeCode,-5}");
            WriteLine($"First Name: {employee.FirstName,20} Employee Code: {employee.EmployeeCode,5}");

            WriteLine($"Productivity rating: {employee.ProductivityRating}");

            const string threePartFormat = "(good employee) #;(bad employee) -#;(new employee - no productivity recorded yet)";

            WriteLine(employee.ProductivityRating.ToString(threePartFormat));


            string skills = "";

            foreach (var skill in employee.Skills)
            {
                skills += $"{skill}, ";
            }

            WriteLine($"Skills: {skills}"); // ignore trailing comma

            var sb = new StringBuilder();

            foreach (var skill in employee.Skills)
            {
                sb.Append(skill);
                sb.Append(", ");
            }

            //WriteLine($"Skills: {sb.ToString()}");
            WriteLine($"Skills: {sb}");

            string prod = string.Format(new EmployeeProductivityFormatProvider(),
                                        "Productivity rating: {0}",
                                        employee.ProductivityRating);

            WriteLine(prod);
        }
Example #4
0
 private static void GetBioFor(Employee employee)
 {
     // Simulate getting bio from user-input
     employee.Bio = "A darn hard working employee, dash it the best we have.";
 }