示例#1
0
    void SwapStruct(StructA a, StructA b)
    {
        int temp = a.nData;

        a.nData = b.nData;
        b.nData = temp;
    }
示例#2
0
        public void SetFirstLevelProperty_Success()
        {
            var structA = new StructA();
            var actual  = structA.Remute(x => x.Value, true);

            Assert.AreNotSame(structA, actual);
            Assert.AreEqual(true, actual.Value);
        }
示例#3
0
        static StructA StructTest9Sub2(ClassA a)
        {
            StructA s = new StructA()
            {
                A = a,
            };

            return(s);
        }
示例#4
0
    public static void ApplyNestedStruct()
    {
        var current = new StructA { a = 2, structB = new StructB { b = 3 } };
        var previous = new StructA { a = 1, structB = new StructB { b = 1 } };

        var delta = SavedObjectDelta.FromObjects(current, previous);
        delta.ApplyChanges(ref previous);

        Assert.AreEqual(current, previous);
    }
    public static void RunTest()
    {
        StructA a = new StructA()
        {
            I1 = 0x11223344, S1 = 0x1122
        };

        Console.WriteLine("a: {0}", a);
        Convert(ref a);
        Console.WriteLine("a: {0}", a);
    }
示例#6
0
        public void Should_support_virtual_calls_with_parameters_on_struct_arguments()
        {
            object aa = new StructA();
            Expression <Func <StructA, bool> > expr = a => a.Equals(aa);

            var f = expr.CompileFast(true);

            Assert.AreEqual(false, f(new StructA {
                N = 42
            }));
        }
        static void Main(string[] args)
        {
            var ca = new ClassA();

            SetName(ca);
            Console.WriteLine($"name in class = {ca.Name}");

            var sa = new StructA();

            SetName(sa);
            Console.WriteLine($"name in struct = {sa.Name}");

            Console.ReadKey();
        }
示例#8
0
    public static void showStruct()
    {
        StructA a = new StructA();
        StructB b = new StructB();
        StructC c = new StructC();

        Console.WriteLine(a);
        Console.WriteLine(b);
        Console.WriteLine(c);
        Console.WriteLine(a.GetType());
        Console.WriteLine(b.GetType());
        Console.WriteLine(c.GetType());
        // Console.WriteLine(a == b); // Can't comparable
        // Console.WriteLine(a == c); // Can't comparabl;
        // Console.WriteLine(b == c); // Can't comparabl;
    }
示例#9
0
    // Use this for initialization
    void Start()
    {
        this.transform.position = new Vector3(0, 0, 0);
        m_sStruct = new StructA(100);
        //m_sStruct.Data = 10;
        SetDataStruct(m_sStruct, 20);
        Debug.Log("StructData" + m_sStruct.Data);
        m_cClass = new ClassA(100);
        //m_cClass.Data = 20;
        SetDataClass(m_cClass, 10);
        Debug.Log("ClassData" + m_cClass.Data);
        string addPlus   = "A" + "d" + "d";
        string addFormat = string.Format("{0}{1}{2}", "A", "d", "d");

        Debug.Log(string.Format("{0}/{1}", addPlus, addFormat));
    }
示例#10
0
        /// <summary>
        /// 参数传递
        /// </summary>
        ///<remarks>
        /// 类是引用类型,作为参数时按引用传递
        /// 结构是值类型,作为参数时按值传递
        ///</remarks>
        public void ParameterPassing()
        {
            ClassA classA = new() { Age = 1 };

            ClassA.ChangeAge(classA);
            // output=100,TestA是类按引用传递
            Console.WriteLine(classA.Age);
            Assert.AreEqual(100, classA.Age);

            StructA structA = new() { Age = 1 };

            StructA.ChangeAge(structA);
            // output=1,StructA是结构按值传递
            Console.WriteLine(structA.Age);
            Assert.AreEqual(1, structA.Age);
        }

        [TestMethod]
示例#11
0
    public static void ApplyNestedStruct()
    {
        var current = new StructA {
            a = 2, structB = new StructB {
                b = 3
            }
        };
        var previous = new StructA {
            a = 1, structB = new StructB {
                b = 1
            }
        };

        var delta = SavedObjectDelta.FromObjects(current, previous);

        delta.ApplyChanges(ref previous);

        Assert.AreEqual(current, previous);
    }
示例#12
0
    Dictionary <string, ClassA> m_dicClassA; //std::map와 같다.

    // Use this for initialization
    void Start()
    {
        //모노비헤이비어로 부터 상속받은 멤버들.
        //컴포넌트나 게임오브젝트 정보등을 가지고 있다.
        this.transform.position = new Vector3(0, 0, 0);
        //구조체는 정적할당됨.
        m_sStruct = new StructA(200);//생성자함수호출
        //m_sStruct.Data = 10; //셋터사용
        SetDataStruct(m_sStruct, 20);
        Debug.Log("StructData:" + m_sStruct.Data); //겟터사용
        m_cClass = new ClassA(100);                //인스턴스 생성(동적할당)
        //생성된 인스턴스는 가비지컬렉션에의해 관리되므로 해제할필요없다.
        //m_cClass.Data = 20;
        SetDataClass(m_cClass, 10);
        Debug.Log("ClassData:" + m_cClass.Data);
        //1.더하기를 하여 문자열를 생성
        string addPlus = "A" + "d" + "d";
        //2.포맷함수를 이용하여 문자열생성: 문자열을 합칠때는 이러한형식을 쓰는것이 오버헤드가 적다.
        string addFormat = string.Format("{0}{1}{2}", "A", "d", "d");

        Debug.Log(string.Format("{0}/{1}", addPlus, addFormat));
    }
示例#13
0
    Dictionary <string, classA> m_dicclassA; //std::map
    // Use this for initialization
    void Start()
    {
        //MonoBehaviour로 부터 상속받은 멤버들.
        //컴포넌트나 게임오브젝트 정보등을 가지고 있다.
        this.transform.position = new Vector3(0, 0, 0);

        //구조체는 정적할당됨.
        m_sStruct = new StructA(200);//생성자함수호출
        //m_sStruct.Data = 10;//set사용
        SetDataStruct(m_sStruct, 20);
        Debug.Log("StructData:" + m_sStruct.Data); //get사용
        m_cClass = new classA(100);                //인스턴스(동적할당)
        //생성된 인스턴스는 가비지컬렉션에 의해 관리되므로 해제할 필요가 없다
        //m_cClass.Data = 20;
        SetDataClass(m_cClass, 10);
        Debug.Log("ClassData:" + m_cClass.Data);
        string addplus   = "A" + "d" + "d";                           //더하기를 하여 문자열을 생성
        string addformat = string.Format("{0}{1}{2}", "A", "d", "d"); //포맷함수를 이용하여 문자열생성

        //문자열을 합칠때는 이러한형식을 쓰는것이 오버헤드가 적다.
        Debug.Log(string.Format("{0}/{1}", addplus, addformat));
    }
示例#14
0
文件: Type.cs 项目: hythof/csharp
 public static void showStruct()
 {
     StructA a = new StructA();
     StructB b = new StructB();
     StructC c = new StructC();
     Console.WriteLine(a);
     Console.WriteLine(b);
     Console.WriteLine(c);
     Console.WriteLine(a.GetType());
     Console.WriteLine(b.GetType());
     Console.WriteLine(c.GetType());
     // Console.WriteLine(a == b); // Can't comparable
     // Console.WriteLine(a == c); // Can't comparabl;
     // Console.WriteLine(b == c); // Can't comparabl;
 }
 private static void SetName(StructA ca) => ca.Name = "Klen";
示例#16
0
文件: Struct.cs 项目: shupoval/Remute
 public StructB(string id, StructA structA)
 {
     Id      = id;
     StructA = structA;
 }
示例#17
0
 void SetDataStruct(StructA s, int data)
 {
     s.Data = data;
 }
示例#18
0
 public static void ChangeAge(StructA testA)
 {
     testA.Age = 100;
 }