Example #1
0
        static void Main(string[] args)
        {
            CollegeStudent student = new CollegeStudent("Name 1");

            // v1.0
            //student.ValueChanged += new ValueChangedDelegate(OnValueChanged);
            //student.ValueChanged += new ValueChangedDelegate(OnValueChanged1);

            // v2.0
            student.ValueChanged += OnValueChanged;
            student.ValueChanged += OnValueChanged1;

            try
            {
                student.Age = 0;
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
            }

            student.Age = 37;
            student.Age = 40;

            // v1.0
            //TestWritingToAFileV1();

            // v2.0
            TestWritingToAFileV2();
        }
Example #2
0
        private static void TestWritingToAFileV2()
        {
            CollegeStudent student = new CollegeStudent("Name 2");

            // Prefer using "using" block for unmanaged code block which uses IDisposable interface
            using (StreamWriter outputFile = File.CreateText("student.txt"))
            {
                student.WriteName(outputFile);
            }
        }
Example #3
0
        private static void TestWritingToAFileV1()
        {
            CollegeStudent student = new CollegeStudent("Name 2");

            StreamWriter outputFile;

            outputFile = File.CreateText("student.txt");

            try
            {
                student.WriteName(outputFile);
            }
            finally
            {
                outputFile.Close();
            }
        }