Exemplo n.º 1
0
 static void Main(string[] args)
 {
     object[] test = new object[5];
     test[0] = (int)1;
     test[1] = (float)0.1;
     test[2] = (string)"hello";
     test[3] = new St1();
     test[4] = new Class1();
     for (int i = 0 ; i < 5 ; i++) {
         Console.WriteLine("Class={0}, Value={1}" , test[i].GetType().FullName , test[i].ToString());
     }
 }
 static void Main(string[] args)
 {
     St1 x = (St1)StructFactory.Default[1];
     St2 y = (St2)StructFactory.Default[2];
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Student stu  = new Student();
            Type    type = stu.GetType();
            var     p    = type.GetProperties();

            foreach (var i in p)
            {
                Console.WriteLine(i.Name);
            }

            Console.WriteLine();

            St1 n = new St1();

            n.name = "SunTaicheng";
            n.age  = 20;

            int mun = 0;

            foreach (var i in p)
            {
                if (mun == 0)
                {
                    i.SetValue(stu, n.name, null);
                }
                else
                {
                    i.SetValue(stu, n.age, null);
                }
                mun++;
            }

            Console.WriteLine(stu.StuName);
            Console.WriteLine(stu.StuAge);

            Console.WriteLine("==================================");
            string a     = "[Config]=90";
            int    index = a.IndexOf('=');

            Console.WriteLine(index);
            Console.WriteLine("pause");
            Console.ReadLine();
            if (index <= 0)
            {
                return;
            }
            Console.WriteLine("Key=" + a.Substring(0, index));
            Console.WriteLine("Value=" + a.Substring(index + 1));
            Console.WriteLine();
            Console.WriteLine("==================================");
            FileStream fs  = new FileStream("a.dll", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
            string     ass = "Hello";
            //byte[] bytes = Encoding.Unicode.GetBytes("hello");
            StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);

            sw.Write(ass);
            sw.Flush();
            sw.Close();

            Console.ReadKey();
        }