⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 program.cs

📁 C#高级编程第6版随书源代码 值得下载
💻 CS
字号:
using System;
using System.Transactions;

namespace Wrox.ProCSharp.Transactions
{
    class Program
    {
         static void Main()
        {
            UseTransactional();
           
  
        }

        private static void UseTransactional()
        {
            Transactional<int> intVal = new Transactional<int>(1);
            Transactional<Student> student1 = new Transactional<Student>(new Student());
            student1.Value.FirstName = "Andrew";
            student1.Value.LastName = "Wilson";

            Console.WriteLine("before the transaction, value: {0}", intVal.Value);
            Console.WriteLine("before the transaction, student: {0}", student1.Value);

            using (TransactionScope scope = new TransactionScope())
            {
                intVal.Value = 2;
                Console.WriteLine("inside transaction, value: {0}", intVal.Value);

                student1.Value.FirstName = "Ten";
                student1.Value.LastName = "Sixty-Nine";

                if (!Utilities.AbortTx())
                    scope.Complete();
            }
            Console.WriteLine("outside of transaction, value: {0}", intVal.Value);
            Console.WriteLine("outside of transaction, student: {0}", student1.Value);

        }

        private static void IntDemo1()
        {
            Transactional<int> myint = new Transactional<int>(1);

            Transactional<Student> myStudent = new Transactional<Student>();

            myStudent.Value.FirstName = "Tom";
            myStudent.Value.LastName = "Turbo";

            myint.Value = 2;
            using (TransactionScope scope = new TransactionScope())
            {
                Transactional<string> mystring = new Transactional<string>("one");

                Console.WriteLine(myint.Value);
                myint.Value = 5;
                Console.WriteLine(myint.Value);

                using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    Console.WriteLine(mystring);
                    Console.WriteLine(myint.Value);
                    scope2.Complete();
                }

                // scope.Complete();
            }
            Console.WriteLine(myint.Value);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -