예제 #1
0
파일: Program.cs 프로젝트: PreeduS/csharp
        static void Main(string[] args)
        {
            //value type
            //no var initialization
            //no 0 params constructor
            //no class/struct inheritance
            //can be used without new

            PersonS s = new PersonS("Bob", "Boben");
            PersonC c = new PersonC("Bob", "Boben");


            Console.WriteLine($"Struct name = {s.Name}");               //Bob
            UpdateS(s);
            Console.WriteLine($"Struct name after change = {s.Name}");  //Bob

            Console.WriteLine();


            Console.WriteLine($"Class name = {c.Name}");                //Bob
            UpdateC(c);
            Console.WriteLine($"Class name after change = {c.Name}");   //Bob edit

            //no constructor
            TestS ts;

            ts.paramA = "A";
            ts.paramB = "B";
        }
        public void Rec_HappyToDict()
        {
            var p = new PersonC("Joost", "Morsink", 37);

            Assert.IsTrue(converter.Convert(p).TryTo(out Dictionary <string, string> d), "An object should be convertible to a dictionary");
            Assert.AreEqual(3, d.Count, "Number of readable properties should equal the number of entries in the dictionary");
            Assert.AreEqual(p.FirstName, d["FirstName"], "Property value FirstName should be preserved in dictionary");
            Assert.AreEqual(p.LastName, d["LastName"], "Property value LastName should be preserved in dictionary");
            Assert.AreEqual(p.Age.ToString(), d["Age"], "Property value Age should be converted in dictionary");
        }
예제 #3
0
        public void ClonePersonTest()
        {
            var st = new PersonC
            {
                Name = "kaw",
                User = "******",
            };

            st.SetAge(8);
            st.iArr = new int[] { 8, 9, 10 };
            PersonC result2 = st.Clone2();
            var     result  = st.Clone() as PersonC;

            result.Name = "kkx";

            Assert.AreEqual(st.Name, "kaw");
            Assert.AreEqual(result.User, "12");
            Assert.AreEqual(result.Age, 8);
        }
예제 #4
0
파일: Program.cs 프로젝트: PreeduS/csharp
 static void UpdateC(PersonC c)
 {
     c.Name = "Bob edit";
 }