예제 #1
0
 internal PersonDataStruct[] GetPersonsInBatchStructs(int amount)
 {
     PersonDataStruct[] result = new PersonDataStruct[amount];
     for (int i = 0; i < amount; ++i)
     {
         result[i] = new PersonDataStruct()
         {
             Firstname  = "A",
             Lastname   = "B",
             BirthDate  = DateTime.Now.AddYears(20),
             EmployeeId = Guid.NewGuid()
         };
     }
     return(result);
 }
예제 #2
0
        ///////////////////////////////////////////////////////////////////////
        /// Listing 6-11
        public List <string> PeopleEmployeedWithinLocation_Structs(int amount, LocationStruct location)
        {
            List <string> result = new List <string>();

            PersonDataStruct[] input = service.GetPersonsInBatchStructs(amount);
            DateTime           now   = DateTime.Now;

            for (int i = 0; i < input.Length; ++i)
            {
                ref PersonDataStruct item = ref input[i];
                if (now.Subtract(item.BirthDate).TotalDays > 18 * 365)
                {
                    var employee = service.GetEmployeeStruct(item.EmployeeId);
                    if (locationService.DistanceWithStruct(ref location, employee.Address) < 10.0)
                    {
                        string name = string.Format("{0} {1}", item.Firstname, item.Lastname);
                        result.Add(name);
                    }
                }
            }
예제 #3
0
        public void PersonDataStructTest()
        {
            var person1 = new PersonDataStruct()
            {
                Name = "John", Age = 25
            };
            var person2 = new PersonDataStruct()
            {
                Name = "Paul", Age = 36
            };

            //person1 and person2 are obviously not equal
            Assert.AreNotEqual(person1.Age, person2.Age);

            person2     = person1;
            person2.Age = 30;

            //Both persons age still do not match.
            //Only age of person2 has been changed, because a value type is used here (struct).
            Assert.AreNotEqual(person1.Age, person2.Age);
        }