Esempio n. 1
0
    /// <sumary>
    ///  Serialization constructor
    /// </sumary>
    public CheckersBoard(SerializationInfo info, StreamingContext context)
    {
        byte[] tempPieces = new byte [32];

        pieces = (byte[])info.GetValue("pieces", tempPieces.GetType());

        System.Int32 temp = new System.Int32();
        whitePieces   = (int)info.GetValue("whitePieces", temp.GetType());
        blackPieces   = (int)info.GetValue("blackPieces", temp.GetType());
        currentPlayer = (int)info.GetValue("currentPlayer", temp.GetType());
    }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Planet Earth = new Planet("Земля", 21323123123.231f);

            Object a = new Int32();

            Console.WriteLine(a.GetType());
            a.GetType();

            Earth.WriteInfo();
        }
Esempio n. 3
0
 /// <summary>
 /// Obtiene el componente
 /// </summary>
 /// <returns></returns>
 private static string GetComponente()
 {
     Assembly asComponente;
     // Instantiate a target object.
     Int32 Integer1 = new Int32();
     Type Type1;
     // Set the Type instance to the target class type.
     Type1 = Integer1.GetType();
     // Instantiate an Assembly class to the assembly housing the Integer type.  
     asComponente = Assembly.GetAssembly(Integer1.GetType());
     // Return the name of the assembly that is calling the method.
     return Assembly.GetCallingAssembly().FullName.ToString();
 }
Esempio n. 4
0
        static void print_19()
        {
            System.Int32 a = 30;
            int          b = 64;

            WriteLine("TYPE : {0}, Value : {1}", a.GetType(), a);
            WriteLine("TYPE.ToString() : {0}, Value : {1}", a.GetType().ToString(), a);
            WriteLine("TYPE : {0}, Value : {1}", b.GetType(), b);

            System.String s  = "나 스트링";
            string        s2 = "나 스트링2";

            WriteLine("TYPE : {0}, Value : {1}", s.GetType(), s);
            WriteLine("TYPE : {0}, Value : {1}", s2.GetType(), s2);
        }
		public void JaggedArrayAccess()
		{
			TestName("Zero-based one, two, and jagged array access tests");

			Int32 sum = 0;

			Int32[] aint = new Int32[numElements * numElements];
			CodeTimer.Time("1-dim zero-based access: " + aint.GetType(), iterations,
			   () =>
			   {
				   for (Int32 e = 0; e < aint.Length; e++)
					   sum += aint[e];
			   });

			Int32[,] a = new Int32[numElements, numElements];
			CodeTimer.Time("2-dim zero-based access: " + a.GetType(), iterations,
			   () =>
			   {
				   for (Int32 e = 0; e < numElements; e++)
					   for (Int32 f = 0; f < numElements; f++)
						   sum += a[e, f];
			   });

			Int32[][] aJagged = new Int32[numElements][];
			for (Int32 i = 0; i < numElements; i++)
				aJagged[i] = new Int32[numElements];
			CodeTimer.Time("2-dim zero-based jagged access: " + aJagged.GetType(), iterations,
			   () =>
			   {
				   for (Int32 e = 0; e < numElements; e++)
					   for (Int32 f = 0; f < numElements; f++)
						   sum += aJagged[e][f];
			   });
		}
Esempio n. 6
0
        static void Main(string[] args)
        {
            //공용형식 시스템
            System.Int32 a = 123;
            int          b = 456;

            Console.WriteLine("a type:{0}, value:{1}", a.GetType().ToString(), a);
            Console.WriteLine("b type:{0}, value:{1}", b.GetType().ToString(), b);

            System.String c = "abc";
            string        d = "def";

            Console.WriteLine("c type:{0}, value:{1}", c.GetType().ToString(), c);
            Console.WriteLine("d type:{0}, value:{1}", d.GetType().ToString(), d);

            /*
             * C#에서는         (C#)        (C++)
             * System.Int64     long        __int64       (이것도 기억해두기)
             * System.Int32     int         int 또는 long (이것은 기억해두기)
             * System.Int16     short       short
             * System.SByte     sbyte       char
             * System.Byte      byte        unsigned char
             * System.Char      char        wchar_t       (이것도 기억해두기)
             */
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pNameParameter"></param>
        /// <param name="pValuesParameter"></param>
        public void AddParameter(string pNameParameter, Int32?pValuesParameter)
        {
            System.Int32 exemplo         = 0;
            Type         pTypesParameter = exemplo.GetType();

            AddParameter(pNameParameter, pValuesParameter, pTypesParameter);
        }
Esempio n. 8
0
    static void Main()
    {
        var        bool_value   = true; // Note implicit typing here
        const char char_value   = 'x';  // Note the const here
        double     double_value = System.Math.PI;
        var        int_value    = 11;

        System.Int32 int_value_2 = 12;

        Console.WriteLine(bool_value.GetType().ToString());
        Console.WriteLine(char_value.GetType().ToString());
        Console.WriteLine(double_value.GetType().ToString());
        Console.WriteLine(int_value.GetType().ToString());
        Console.WriteLine(int_value_2.GetType().ToString());

        Console.WriteLine(11.GetType().ToString());
        Console.WriteLine(3.1415.GetType().ToString());
        Console.WriteLine('x'.GetType().ToString());

        var string_value = "This is a message!";

        System.String string_value_2 = "This is a second message!";
        object        object_value   = string_value; // Note the use of object here

        Console.WriteLine(string_value.GetType().ToString());
        Console.WriteLine(string_value_2.GetType().ToString());
        Console.WriteLine(object_value.GetType().ToString());
    }
Esempio n. 9
0
        static void F2()
        {
            var v00 = 125;
            // var v0; // Неявно типизированная локальняа переменная var должна быть явным образом проинициализирована
            var v0 = new Int32(); // Неявно типизированная локальная переменная var проинициализирована объектом типа Int(32). По умолчанию ему присваивается значение 0

            Console.WriteLine("the type of v0 is: {0}, value is: {1}", v0.GetType(), v0);
            var v1 = 125; Console.WriteLine("the type of v1 is: {0}, value is: {1}", v1.GetType(), v1);
            var v2 = new float(); Console.WriteLine("the type of v2 is: {0}, value is: {1}", v2.GetType(), v2);
            var v3 = Math.PI; Console.WriteLine("the type of v3 is: {0}, value is: {1}", v3.GetType(), v3);
            var v4 = "qwerty"; Console.WriteLine("the type of v4 is: {0}, value is: {1}", v4.GetType(), v4);
            // Объявление массива также требует явной инициализации
            var v5 = new int[] { }; // Пустой целочисленный массив
            Console.WriteLine("the type of v5 is: {0}", v5.GetType());
            var v6 = new int[] { 1, 2, 3, 4, 5 }; // Целочисленный массив с набором значений.
            Console.WriteLine("the type of v6 is: {0}", v6.GetType());
            var v7 = new[] { 1.1, 2.2, 3.3, 4.4 }; // Массив типа double с набором значений
            Console.WriteLine("the type of v7 is: {0}", v7.GetType());

            // Переменная типа var - применение в цикле
            for(var v = 0; v < 10; v++)
            {
                Console.WriteLine(v);
            }

            // Неявно типизированные даныне var возможны только для локальных переменных методах и свойствах.
            // Переменные var не могут использоваться в качестве возвращаемого значения, параметра метода или члена класса/структуры.
        }
Esempio n. 10
0
    static void Main(string[] args)
    {
        int a = 123;

        System.Int32 b = 123;
        Console.WriteLine("aのフルネームは{0}", a.GetType().FullName);
        Console.WriteLine("bのフルネームは{0}", b.GetType().FullName);
    }
        public void ConstructorTest()
        {
            EditorFactoryNotifyForProjectAttribute target = new EditorFactoryNotifyForProjectAttribute(projectType, fileExtension, factoryType);
            Assert.IsNotNull(target, "Failed to initialize new instance of type EditorFactoryNotifyForProjectAttribute");

            String factoryTypeString = "{3e8702a1-d26f-4b91-bdc2-7ea0022b696c}";
            projectType = new Guid("{3e8702a1-d26f-4b91-bdc2-7ea0022b696c}");
            EditorFactoryNotifyForProjectAttribute targetFromString = new EditorFactoryNotifyForProjectAttribute(projectType, fileExtension, factoryTypeString);
            Assert.IsNotNull(targetFromString, "Failed to initialize new instance of type EditorFactoryNotifyForProjectAttribute from String");

            Int32 integ = new Int32();
            factoryType = integ.GetType();
            projectType = integ.GetType();

            EditorFactoryNotifyForProjectAttribute targetFromType = new EditorFactoryNotifyForProjectAttribute(projectType, fileExtension, factoryType);
            Assert.IsNotNull(targetFromType, "Failed to initialize new instance of type EditorFactoryNotifyForProjectAttribute from Type");
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            System.Int32 a = 123;
            int          b = 456;

            Console.WriteLine("a type:{0}, value:{1}", a.GetType().ToString(), a);
            Console.WriteLine("a type:{0}, value:{1}", a.GetType(), a);
            Console.WriteLine(a.GetType().ToString().GetType());
            Console.WriteLine(a.GetType().GetType());

            Console.WriteLine("b type:{0}, value:{1}", b.GetType().ToString(), b);

            System.String c = "abc";
            string        d = "def";

            Console.WriteLine("c type:{0}, value:{1}", c.GetType().ToString(), c);
            Console.WriteLine("d type:{0}, value:{1}", d.GetType().ToString(), d);
        }
        public void GetType_implications()
        {
            Object o1 = new System.Int32();

            System.Int32 i1 = new System.Int32();

            _output.WriteLine(i1.GetType().ToString()); // Did this get boxed per the requirement?
            _output.WriteLine(IsBoxed(i1).ToString());

            float l2 = ToSingleTest(i1);    // Gets unboxed as it's cast to int parameter?
            float l3 = IntToSingleTest(i1); // It can be param type of Object or Int32
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            int a1 = 13;

            System.Int32 a2 = 14;
            sbyte        a3 = 15;

            System.SByte a4 = 16;

            Console.WriteLine("a1: " + a1.GetType());
            Console.WriteLine("a2: " + a2.GetType());
            Console.WriteLine("a3: " + a3.GetType());
            Console.WriteLine("a4: " + a4.GetType());
        }
Esempio n. 15
0
        public static void CTS()
        {
            System.Int32 a = 123;
            int          b = 456;

            WriteLine("a type : {0}, value : {1}", a.GetType().ToString(), a); // GetType();<-- 해당 변수(객체가 맞는 표현) 실체 형식 알려줌
            WriteLine("b type : {0}, value : {1}", b.GetType().ToString(), b); // ToSring();<-- 변수(객체가 맞는 표현)를 문자열로 표시

            System.String c = "abc";
            string        d = "def";

            WriteLine("c type : {0}, value : {1}", c.GetType().ToString(), c);
            WriteLine("d type : {0}, value : {1}", d.GetType().ToString(), d);
        }
Esempio n. 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pNameParameter"></param>
        /// <param name="pValuesParameter"></param>
        /// <param name="pPermitirValorZero"></param>
        public void AddParameter(string pNameParameter, Int32 pValuesParameter, bool pPermitirValorZero = false)
        {
            System.Int32 exemplo         = 0;
            Type         pTypesParameter = exemplo.GetType();

            if (pValuesParameter > 0 || pPermitirValorZero)
            {
                AddParameter(pNameParameter, pValuesParameter, pTypesParameter);
            }
            else
            {
                AddParameter(pNameParameter, null, pTypesParameter);
            }
        }
Esempio n. 17
0
        private static void CTS()
        {
            Console.WriteLine("\nCTS()");

            System.Int32 a = 123;
            int          b = 456;

            Console.WriteLine("a type : {0}, value : {1}", a.GetType().ToString(), a);
            Console.WriteLine("b type : {0}, value : {1}", b.GetType().ToString(), b);

            System.String c = "abc";
            String        d = "def";

            Console.WriteLine("c type : {0}, value : {1}", c.GetType().ToString(), c);
            Console.WriteLine("d type : {0}, value : {1}", d.GetType().ToString(), d);
        }
Esempio n. 18
0
        public void Print()
        {
            System.Int32 i = new System.Int32();
            i = 23;
            Console.WriteLine(i.GetHashCode());
            Console.WriteLine(i.GetType());
            Console.WriteLine(i.GetTypeCode());
            Console.WriteLine(i.ToString());
            if (i.CompareTo(20) < 0)
                Console.WriteLine("{0} < 20", i);
            else if (i.CompareTo(20) == 0)
                Console.WriteLine("i equals 20");
            else
                Console.WriteLine("i > 20");
            Console.WriteLine(System.Int32.MinValue);
            Console.WriteLine(System.Int32.MaxValue);
            Console.WriteLine(System.Double.Epsilon);
            Console.WriteLine(System.Double.PositiveInfinity);
            Console.WriteLine(System.Double.NegativeInfinity);
            Console.WriteLine(System.Boolean.FalseString);
            Console.WriteLine(System.Boolean.TrueString);

            Console.WriteLine(System.Char.IsDigit('1'));
            Console.WriteLine(System.Char.IsLetter('9'));
            Console.WriteLine(System.Char.IsWhiteSpace("naynish chaughule", 7));
            Console.WriteLine(System.Char.IsPunctuation('?'));

            //parsing
            double d = System.Double.Parse("90.35");
            Console.WriteLine(d);
            System.Int64 longVar = Convert.ToInt64("43654703826562");
            Console.WriteLine(longVar);

            Console.WriteLine(System.Guid.NewGuid());
            System.DateTime dt = new DateTime(2012, 6, 04);
            Console.WriteLine(dt.ToLongDateString());
            Console.WriteLine(DateTime.Now.ToLongTimeString());
            Console.WriteLine(dt.DayOfWeek);
            Console.WriteLine(dt.AddMonths(5).ToLongDateString());
            Console.WriteLine("{0} {1} {2}", dt.Date, dt.DayOfYear, dt.IsDaylightSavingTime());

            TimeSpan ts = new TimeSpan(24, 30, 30);
            Console.WriteLine(dt.Add(ts).ToLongDateString());
            Console.WriteLine(ts.Subtract(new TimeSpan(2,30, 45)));
            NumericsDemo();
            WorkingWithStrings();
        }
Esempio n. 19
0
        static void Main(String[] args)
        {
            // GetType() 해당 객체의 실제 형식을 알려준다.
            // ToString() 변수의 데이터를 문자열로 표시한다.

            System.Int32 a = 123;
            int          b = 456;

            Console.WriteLine($"a type: {a.GetType()} value: {a.ToString()}");
            Console.WriteLine($"b type: {b.GetType()} value: {b.ToString()}");

            System.String c = "abc";
            string        d = "def";

            Console.WriteLine($"a type: {c.GetType()} value: {c.ToString()}");
            Console.WriteLine($"b type: {d.GetType()} value: {d.ToString()}");
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            int n1 = 42;

            Console.WriteLine("01) Type of n1: " + n1.GetType().Name);

            System.Int32 n2 = 127;
            Console.WriteLine("02) Type of n2: " + n2.GetType().Name);

            Type t = n1.GetType();

            WriteTypeInfo(t);

            WriteTypeInfo(new int[5].GetType());

            WriteTypeInfo(new A().GetType());
            WriteTypeInfo(new B().GetType());
            WriteTypeInfo(new S().GetType());

            WriteTypeInfo(new List <string>().GetType());
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            byte   k   = 10;
            string msg = string.Format("k = {0:X}", k);

            Console.WriteLine(msg);

            k = 20;
            Console.WriteLine(msg);
            System.Int32 m = new System.Int32();
            m = 10;
            Console.WriteLine(m);
            Console.WriteLine("k {0}, msg {1}, m {2}", k.GetType(), msg.GetType(), m.GetType());

            Console.WriteLine("Positive infinity: {0}\nNegative infinity: {1}\n{2}", double.PositiveInfinity, double.NegativeInfinity, double.PositiveInfinity * double.PositiveInfinity);

            char a = 'a';

            Console.WriteLine("char.IsDigit(a) {0}", char.IsDigit(a));
            Console.WriteLine(char.IsSymbol("!!!!!!", 3));
        }
Esempio n. 22
0
    public bool PosTest1()
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("Verify GetType method return correct system instance type...");

        try
        {
            Int32 intInstance = new Int32();
            Type instanceType = intInstance.GetType();

            if (instanceType.FullName != "System.Int32")
            {
                TestLibrary.TestFramework.LogError("001","Fetch the wrong Type of instance!");
                retVal = true;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002","Unexpected exception occurs: " + e);
            retVal = false;
        }

        return retVal;
    }
Esempio n. 23
0
        static void Main(string[] args)
        {
            Type t1 = typeof(String);

            Object o = null;

            Random r = new Random();

            switch (r.Next(1, 4))
            {
                case 1:
                    o = new Object();
                    break;
                case 2:
                    o = new Random();
                    break;
                case 3:
                    o = new Int32();
                    break;
            }

            Type t2 = o.GetType();

            Type t3 = Type.GetType("system.int32", false, true);

            Type t4 = Type.GetType("_252_GetType.Externa", false, true);
            Type t5 = Type.GetType("_252_GetType.Externa+Interna", false, true);

            MostrarDados(t1);
            MostrarDados(t2);
            MostrarDados(t3);
            MostrarDados(t4);
            MostrarDados(t5);

            Console.ReadKey();
        }
Esempio n. 24
0
        public override void RunCode(int arg)
        {
            switch (arg)
            {
            case 48:
            {
                sbyte a48 = -10;
                byte  b48 = 40;

                Console.WriteLine($"a={a48}, b={b48}");

                short  c48 = -30000;
                ushort d48 = 60000;

                Console.WriteLine($"c={c48}, d={d48}");

                int  e48 = -1000_0000;
                uint f48 = 3_0000_0000;

                Console.WriteLine($"e={e48}, f={f48}");

                long  g48 = -5000_0000_0000;
                ulong h48 = 200_0000_0000_0000_0000;

                Console.WriteLine($"g={g48}, h={h48}");
            }
            break;

            case 50:
            {
                byte a50 = 240;
                Console.WriteLine($"a={a50}");

                byte b50 = 0b1111_0000;             // 2진수 리터럴
                Console.WriteLine($"b={b50}");

                byte c50 = 0XF0;                    // 16진수 리터럴
                Console.WriteLine($"c={c50}");

                uint d50 = 0x1234_abcd;             // 16진수 리터럴
                Console.WriteLine($"d={d50}");
            }
            break;

            case 54:
            {
                byte  a54 = 255;
                sbyte b54 = (sbyte)a54;

                Console.WriteLine(a54);
                Console.WriteLine(b54);
            }
            break;

            case 55:
            {
                uint a55 = uint.MaxValue;

                Console.WriteLine(a55);

                a55 = a55 + 1;

                Console.WriteLine(a55);
            }
            break;

            case 58:
            {
                float a58 = 3.1415_9265_3589_7932_7846f;
                Console.WriteLine(a58);

                double b58 = 3.1415_9265_3589_7932_3846;
                Console.WriteLine(b58);
            }
            break;

            case 60:
            {
                float   a60 = 3.1415_9265_3589_7932_3846_2643_3832_79f;
                double  b60 = 3.1415_9265_3589_7932_3846_2643_3832_79;
                decimal c60 = 3.1415_9265_3589_7932_3846_2643_3832_79m;

                Console.WriteLine(a60);
                Console.WriteLine(b60);
                Console.WriteLine(c60);
            }
            break;

            case 61:
            {
                char a61 = '안';
                char b61 = '녕';
                char c61 = '하';
                char d61 = '세';
                char e61 = '요';

                Console.Write(a61);
                Console.Write(b61);
                Console.Write(c61);
                Console.Write(d61);
                Console.Write(e61);
                Console.WriteLine();
            }
            break;

            case 63:
            {
                string a63 = "안녕하세요?";
                string b63 = "Hamm입니다.";

                Console.WriteLine(a63);
                Console.WriteLine(b63);
            }
            break;

            case 65:
            {
                bool a65 = true;
                bool b65 = false;

                Console.WriteLine(a65);
                Console.WriteLine(b65);
            }
            break;

            case 67:
            {
                object a67 = 123;
                object b67 = 3.141592653589793238462643383279m;
                object c67 = true;
                object d67 = "안녕하세요";

                Console.WriteLine(a67);
                Console.WriteLine(b67);
                Console.WriteLine(c67);
                Console.WriteLine(d67);
            }
            break;

            case 69:
            {
                int    a69 = 123;
                object b69 = (object)a69;               // a에 담긴 값을 박싱해서 힙에 저장
                int    c69 = (int)b69;                  // b에 담긴 값을 언박싱해서 스택에 저장

                Console.WriteLine(a69);
                Console.WriteLine(b69);
                Console.WriteLine(c69);

                double x69 = 3.141213;
                // object 형식에 저장할 때 형식 변환 연산자를 지정하지 않으면
                // 암시적으로 object 형식으로 변환된다.
                object y69 = x69;                       // x에 담긴 값을 박싱해서 힙에 저장
                double z69 = (double)y69;               // y에 담긴 값을 언박싱해서 스택에 저장

                Console.WriteLine(x69);
                Console.WriteLine(y69);
                Console.WriteLine(z69);
            }
            break;

            case 71:
            {
                sbyte a71 = 127;
                Console.WriteLine(a71);

                int b71 = (int)a71;
                Console.WriteLine(b71);

                int x71 = 128;                      // sbyte의 최대값 127보다 1 큰 수
                Console.WriteLine(x71);

                sbyte y71 = (sbyte)x71;             // 오버플로우 발생
                Console.WriteLine(y71);
            }
            break;

            case 72:
            {
                float a72 = 69.6875f;
                Console.WriteLine("a : {0}", a72);

                double b72 = (double)a72;
                Console.WriteLine("b : {0}", b72);

                Console.WriteLine("69.6875 == b : {0}", 69.6875 == b72);

                float x72 = 0.1f;
                Console.WriteLine("x ; {0}", x72);

                double y72 = (double)x72;
                Console.WriteLine("y : {0}", y72);

                Console.WriteLine("0.1 == y : {0}", 0.1 == y72);
            }
            break;

            case 74:
            {
                int a74 = 500;
                Console.WriteLine(a74);

                uint b74 = (uint)a74;
                Console.WriteLine(b74);

                int x74 = -30;
                Console.WriteLine(x74);

                uint y74 = (uint)x74;               // 언더플로우
                Console.WriteLine(y74);
            }
            break;

            case 75:
            {
                float a75 = 0.9f;
                int   b75 = (int)a75;
                Console.WriteLine(b75);

                float c75 = 1.1f;
                int   d75 = (int)c75;
                Console.WriteLine(d75);
            }
            break;

            case 77:
            {
                int    a77 = 123;
                string b77 = a77.ToString();
                Console.WriteLine(b77);

                float  c77 = 3.14f;
                string d77 = c77.ToString();
                Console.WriteLine(d77);

                string e77 = "123456";
                int    f77 = Convert.ToInt32(e77);
                Console.WriteLine(f77);

                string g77 = "1.2345";
                float  h77 = float.Parse(g77);
                Console.WriteLine(h77);
            }
            break;

            case 79:
            {
                const int MAX_INT = 2147483647;
                const int MIN_INT = -2147483648;

                Console.WriteLine(MAX_INT);
                Console.WriteLine(MIN_INT);
            }
            break;

            case 82:
            {
                Console.WriteLine((int)DialogResult82.YES);
                Console.WriteLine((int)DialogResult82.NO);
                Console.WriteLine((int)DialogResult82.CANCEL);
                Console.WriteLine((int)DialogResult82.CONFIRM);
                Console.WriteLine((int)DialogResult82.OK);
            }
            break;

            case 83:
            {
                DialogResult82 result = DialogResult82.YES;

                Console.WriteLine(result == DialogResult82.YES);
                Console.WriteLine(result == DialogResult82.NO);
                Console.WriteLine(result == DialogResult82.CANCEL);
                Console.WriteLine(result == DialogResult82.CONFIRM);
                Console.WriteLine(result == DialogResult82.OK);
            }
            break;

            case 87:
            {
                int?a87 = null;

                Console.WriteLine(a87.HasValue);
                Console.WriteLine(a87 != null);

                a87 = 3;

                Console.WriteLine(a87.HasValue);
                Console.WriteLine(a87 != null);
                Console.WriteLine(a87.Value);
            }
            break;

            case 89:
            {
                var a89 = 20;               // var로 선언하는 변수는 반드시 초기화해야 한다.
                Console.WriteLine("Type : {0}, Value : {1}", a89.GetType(), a89);

                var b89 = 3.1414213;
                Console.WriteLine("type : {0}, Value : {1}", b89.GetType(), b89);

                var c89 = "Hello, World!";
                Console.WriteLine("type : {0}, Value : {1}", c89.GetType(), c89);

                var d89 = new int[] { 10, 20, 30 };
                Console.WriteLine("type : {0}, Value : {1}", d89.GetType(), d89);

                foreach (var e89 in d89)
                {
                    Console.Write("{0} ", e89);
                }

                Console.WriteLine();
            }
            break;

            case 92:
            {
                System.Int32 a92 = 123;
                int          b92 = 456;

                Console.WriteLine("a92 type:{0}, value:{1}", a92.GetType().ToString(), a92);
                Console.WriteLine("b92 type:{0}, value:{1}", b92.GetType().ToString(), b92);

                System.String c92 = "abc";
                string        d92 = "def";

                Console.WriteLine("c92 type:{0}, value:{1}", c92.GetType().ToString(), c92);
                Console.WriteLine("d92 type:{0}, value:{1}", d92.GetType().ToString(), d92);
            }
            break;
            }
        }
Esempio n. 25
0
        static void Main(string[] args)
        {
            bool a = true;

            System.Boolean a1 = false;
            System.Type[]  a2 = { a.GetType(), a1.GetType() };
            foreach (var item in a2)
            {
                Console.Write(item.ToString() + "\n");
            }

            byte b = 10;

            System.Byte   b1 = 11;
            System.Type[] b2 = { b.GetType(), b1.GetType() };
            foreach (var item in b2)
            {
                Console.Write(item.ToString() + "\n");
            }

            sbyte c = 22;

            System.SByte  c1 = 23;
            System.Type[] c2 = { c.GetType(), c1.GetType() };
            foreach (var item in c2)
            {
                Console.Write(item.ToString() + "\n");
            }

            short d = -33;

            System.Int16  d1 = -34;
            System.Type[] d2 = { d.GetType(), d1.GetType() };
            foreach (var item in d2)
            {
                Console.Write(item.ToString() + "\n");
            }

            ushort e = 33;

            System.UInt16 e1 = 34;
            System.Type[] e2 = { e.GetType(), e1.GetType() };
            foreach (var item in e2)
            {
                Console.Write(item.ToString() + "\n");
            }

            int f = 44;

            System.Int32  f1 = 45;
            System.Type[] f2 = { f.GetType(), f1.GetType() };
            foreach (var item in f2)
            {
                Console.Write(item.ToString() + "\n");
            }

            uint g = 55;

            System.UInt32 g1 = 56;
            System.Type[] g2 = { g.GetType(), g1.GetType() };
            foreach (var item in g2)
            {
                Console.Write(item.ToString() + "\n");
            }

            long h = -555;

            System.Int64  h1 = -556;
            System.Type[] h2 = { h.GetType(), h1.GetType() };
            foreach (var item in h2)
            {
                Console.Write(item.ToString() + "\n");
            }

            ulong i = 555;

            System.UInt64 i1 = 556;
            System.Type[] i2 = { i.GetType(), i1.GetType() };
            foreach (var item in i2)
            {
                Console.Write(item.ToString() + "\n");
            }

            float j = 666;

            System.Single j1 = 667;
            System.Type[] j2 = { j.GetType(), j1.GetType() };
            foreach (var item in j2)
            {
                Console.Write(item.ToString() + "\n");
            }

            double k = 777;

            System.Double k1 = 778;
            System.Type[] k2 = { k.GetType(), k1.GetType() };
            foreach (var item in k2)
            {
                Console.Write(item.ToString() + "\n");
            }

            decimal l = 888;

            System.Decimal l1 = 889;
            System.Type[]  l2 = { l.GetType(), l1.GetType() };
            foreach (var item in l2)
            {
                Console.Write(item.ToString() + "\n");
            }

            char m = 'a';

            System.Char   m1 = 'b';
            System.Type[] m2 = { m.GetType(), m1.GetType() };
            foreach (var item in m2)
            {
                Console.Write(item.ToString() + "\n");
            }

            string n = "Hello";

            System.String n1 = "Bye";
            System.Type[] n2 = { n.GetType(), n1.GetType() };
            foreach (var item in n2)
            {
                Console.Write(item.ToString() + "\n");
            }

            Console.ReadLine();
        }
Esempio n. 26
0
		public void TestSkin ()
		{
			Assembly SampleAssembly;
			// Instantiate a target object.
			Int32 Integer1 = new Int32 ();
			Type Type1;
			// Set the Type instance to the target class type.
			Type1 = Integer1.GetType ();
			// Instantiate an Assembly class to the assembly housing the Integer type.  
			SampleAssembly = Assembly.GetAssembly (Integer1.GetType ());
			// Display the physical location of the assembly containing the manifest.
			Console.WriteLine ("Location=" + SampleAssembly.Location);



			WebTest.CopyResource (GetType (), "Test1.Resources.Default.skin", "App_Themes/Black/Default.skin");
			WebTest.CopyResource (GetType (), "Test1.Resources.MyPageWithTheme.aspx", "MyPageWithTheme.aspx");
			string res = new WebTest ("MyPageWithTheme.aspx").Run ();
			Debug.WriteLine (res);			
		}
Esempio n. 27
0
        static void Main(string[] args)
        {
            // 정수 데이터 타입
            sbyte id_a = -10;
            byte  id_b = 40;

            Console.WriteLine($"id_a={id_a}, id_b={id_b}");

            short  id_c = -30000;
            ushort id_d = 60000;

            Console.WriteLine($"id_c={id_c}, id_d={id_d}");

            int  id_e = -10_000_000;
            uint id_f = 300_000_000;

            Console.WriteLine($"id_e={id_e}, id_f={id_f}");

            long  id_g = -5000_0000_0000;
            ulong id_h = 200_0000_0000_0000_0000;

            Console.WriteLine($"id_g={id_g}, id_h={id_h}");

            // 2진수, 10진수, 16진수 리터럴
            byte dl_a = 240;

            Console.WriteLine("dl_a={0}", dl_a);

            byte dl_b = 0b1111_0000;

            Console.WriteLine("dl_b={0}", dl_b);

            byte dl_c = 0XF0;

            Console.WriteLine("dl_c={0}", dl_c);

            uint dl_d = 0x1234_abcd;

            Console.WriteLine("dl_d={0}", dl_d);

            // 오버플로우
            int overflow = int.MaxValue;

            Console.WriteLine(overflow);

            overflow++;
            Console.WriteLine(overflow);

            // 부동 소수점 형식
            float fp_a = 3.1415_9265_3589_7932_3846_2643_3832_79f;

            Console.WriteLine(fp_a);

            double fp_b = 3.1415_9265_3589_7932_3846_2643_3832_79;

            Console.WriteLine(fp_b);

            decimal fp_c = 3.1415_9265_3589_7932_3846_2643_3832_79m;

            Console.WriteLine(fp_c);

            // 문자와 문자열
            char cs_a = '안';
            char cs_b = '녕';

            Console.WriteLine("{0}{1}", cs_a, cs_b);

            string cs_c = "안녕";

            Console.WriteLine(cs_c);

            // 논리 형식
            bool bl_a = true;
            bool bl_b = false;

            Console.WriteLine("{0}, {1}", bl_a, bl_b);

            // object와 박싱, 언박싱
            object ob_a = 123;
            int    ob_b = (int)ob_a;

            Console.WriteLine("{0}, {1}", ob_a, ob_b);

            // 숫자와 문자열 간의 변환
            int    ns_a = 12345;
            string ns_b = ns_a.ToString();

            Console.WriteLine(ns_b);

            int ns_c = int.Parse(ns_b);

            Console.WriteLine(ns_c);

            // 상수
            const int li_a = 100;

            Console.WriteLine(li_a);

            // 열거형
            En_a En_b = En_a.TWO;

            Console.WriteLine(En_b == En_a.ONE);
            Console.WriteLine(En_b == En_a.TWO);

            // Nullable
            int?nu_a = null;

            Console.WriteLine("{0}", nu_a.HasValue);

            nu_a = 15;
            Console.WriteLine("{0}", nu_a.HasValue);

            // var
            var va_a = 3;

            Console.WriteLine("Type: {0}, Value: {1}", va_a.GetType(), va_a);

            var va_b = 3.14;

            Console.WriteLine("Type: {0}, Value: {1}", va_b.GetType(), va_b);

            var va_c = "PI";

            Console.WriteLine("Type: {0}, Value: {1}", va_c.GetType(), va_c);

            // CTS(공용 형식 시스템)
            System.Int32 ct_a = 50;
            Console.WriteLine("Type: {0}, Value: {1}", ct_a.GetType(), ct_a);

            System.String ct_b = "CTS";
            Console.WriteLine("Type: {0}, Value: {1}", ct_b.GetType(), ct_b);
        }
Esempio n. 28
0
 public Type GetType()
 {
     return(m_v.GetType());
 }
Esempio n. 29
0
        static void Main(string[] args)
        {
            // объявляю все переменные двумя способами

            sbyte a1 = 1;

            System.SByte a2 = 2;

            short b1 = 3;

            System.Int16 b2 = 4;

            int c1 = 5;

            System.Int32 c2 = 6;

            long d1 = 7;

            System.Int64 d2 = 8;

            byte e1 = 9;

            System.Byte e2 = 10;

            ushort f1 = 11;

            System.UInt16 f2 = 12;

            uint g1 = 13;

            System.UInt32 g2 = 14;

            ulong h1 = 15;

            System.UInt64 h2 = 16;

            char i1 = 'A';

            System.Char i2 = 'B';

            float j1 = 17.1F;

            System.Single j2 = 17.2F;

            double k1 = 17.11;

            System.Double k2 = 17.22;

            bool l1 = false;

            System.Boolean l2 = true;

            decimal m1 = 1.1M;

            System.Decimal m2 = 2.2M;

            object n1 = 18;

            System.Object n2 = 19;

            string o1 = "Hi!";

            System.String o2 = "Bye!";

            //получаю типы этих переменных

            Type nameA1 = a1.GetType();
            Type nameA2 = a2.GetType();

            Type nameB1 = b1.GetType();
            Type nameB2 = b2.GetType();

            Type nameC1 = c1.GetType();
            Type nameC2 = c2.GetType();

            Type nameD1 = d1.GetType();
            Type nameD2 = d2.GetType();

            Type nameE1 = e1.GetType();
            Type nameE2 = e2.GetType();

            Type nameF1 = f1.GetType();
            Type nameF2 = f2.GetType();

            Type nameG1 = g1.GetType();
            Type nameG2 = g2.GetType();

            Type nameH1 = h1.GetType();
            Type nameH2 = h2.GetType();

            Type nameI1 = i1.GetType();
            Type nameI2 = i2.GetType();

            Type nameJ1 = j1.GetType();
            Type nameJ2 = j2.GetType();

            Type nameK1 = k1.GetType();
            Type nameK2 = k2.GetType();

            Type nameL1 = l1.GetType();
            Type nameL2 = l2.GetType();

            Type nameM1 = m1.GetType();
            Type nameM2 = m2.GetType();

            Type nameN1 = n1.GetType();
            Type nameN2 = n2.GetType();

            Type nameO1 = o1.GetType();
            Type nameO2 = o2.GetType();

            //вывожу типы переменных на консоль

            Console.WriteLine(nameA1);
            Console.WriteLine(nameA2);
            Console.WriteLine(nameB1);
            Console.WriteLine(nameB2);
            Console.WriteLine(nameC1);
            Console.WriteLine(nameC2);
            Console.WriteLine(nameD1);
            Console.WriteLine(nameD2);
            Console.WriteLine(nameE1);
            Console.WriteLine(nameE2);
            Console.WriteLine(nameF1);
            Console.WriteLine(nameF2);
            Console.WriteLine(nameG1);
            Console.WriteLine(nameG2);
            Console.WriteLine(nameH1);
            Console.WriteLine(nameH2);
            Console.WriteLine(nameI1);
            Console.WriteLine(nameI2);
            Console.WriteLine(nameJ1);
            Console.WriteLine(nameJ2);
            Console.WriteLine(nameK1);
            Console.WriteLine(nameK2);
            Console.WriteLine(nameL1);
            Console.WriteLine(nameL2);
            Console.WriteLine(nameM1);
            Console.WriteLine(nameM2);
            Console.WriteLine(nameN1);
            Console.WriteLine(nameN2);
            Console.WriteLine(nameO1);
            Console.WriteLine(nameO2);
        }
Esempio n. 30
0
        public MFTestResults SystemType6_GetElementType_Test()
        {
            /// <summary>
            ///  1. Tests the GetElementType() method for a user defined type
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                Log.Comment("This tests the GetElementType() method");
                
                //Assigned and manipulated to avoid compiler warning
                Int32 testInt32 = -1;
                testInt32++;

                Type myType1 = Type.GetType("System.Int32");
                Log.Comment("The full name is " + myType1.FullName);
                Int32[] int32Arr = new Int32[] { };
                Type int32ArrType = int32Arr.GetType();
                testResult &= (myType1 == int32ArrType.GetElementType());

                testResult &= (myType1.GetElementType() == null); 
            }
            catch (Exception e)
            {
                Log.Comment("Typeless " + e.Message); 
                testResult = false;
            }

            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
 public bool runTest()
   {
   Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   Type ArrType;
   try {
   do
     {
     strLoc = "Loc_01T";
     iCountTestcases++;
     short [] in2Arr = new Int16[10];
     ArrType = in2Arr.GetType();
     if(!ArrType.IsArray)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ " ,Err_01T! , Array.GetType failed on single dimension array." );
       }
     strLoc = "Loc_02T";
     iCountTestcases++;
     int[] in4Arr = new Int32[0];
     ArrType = in4Arr.GetType();
     if(!ArrType.IsArray)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ " ,Err_02T! , Array.GetType failed on 0 size single dimension array." );
       }
     int[][] i4Arr = new int[3][];
     i4Arr[0] = new int[] {1, 2, 3};
     i4Arr[1] = new int[] {1, 2, 3, 4, 5, 6};
     i4Arr[2] = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9};
     strLoc = "Loc_03T";
     iCountTestcases++;
     ArrType = i4Arr.GetType();
     if(!ArrType.IsArray)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ " ,Err_03ifs! , Array.GetType failed on jagged array." );
       }
     strLoc = "Loc_04ifx";
     iCountTestcases++;
     Object [][] objArr = new Object[0][];
     ArrType = objArr.GetType();
     if(!ArrType.IsArray)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ " ,Err_04ifs! , Array.GetType failed on 0 size jagged array." );
       }
     strLoc = "Loc_05ifx";
     iCountTestcases++;
     Double[,] doArr = new Double[99, 78];
     ArrType = doArr.GetType();
     if(!ArrType.IsArray)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ " ,Err_05ifs! , Array.GetType failed on rectangle array." );
       }
     strLoc = "Loc_06ifx";
     iCountTestcases++;
     Hashtable[,] htArr = new Hashtable[0,0];
     ArrType = htArr.GetType();
     if(!ArrType.IsArray)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ " ,Err_06ifs! , Array.GetType failed on 0 size rectangle array." );
       }
     strLoc = "Loc_07ifx";
     iCountTestcases++;
     string[,,,,,] strArr = new string[6,5,4,3,2,1];
     ArrType = strArr.GetType();
     if(!ArrType.IsArray)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ " ,Err_07ifs! , Array.GetType failed on 6 dimensions rectangle array." );
       }
     strLoc = "Loc_08ifx";
     iCountTestcases++;
     ArrType = typeof(System.Array);
     if(ArrType.IsArray)
       { 
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ " ,Err_08ifs! , typeof(System.Array).IsArray should return false." );
       }
     strLoc = "Loc_09ifx";
     iCountTestcases++;
     int [] dims = {2,3,2,1};
     int [] lbould = {0,1,2,3};
     Array dbArr = Array.CreateInstance(typeof(Double), dims, lbould);
     ArrType = dbArr.GetType();
     if(!ArrType.IsArray)
       {
       iCountErrors++;
       Console.WriteLine( s_strTFAbbrev+ " ,Err_09ifs! , Array.GetType failed on multi_dimensions rectangle array created by Array.CreateInstance." );
       }
     } while (false);
   } catch (Exception exc_general ) {
   ++iCountErrors;
   Console.WriteLine(s_strTFAbbrev +" Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general);
   }
   if ( iCountErrors == 0 )
     {
     Console.Error.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
     return true;
     }
   else
     {
     Console.Error.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,inCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
        static void Main(string[] args)
        {
            sbyte a1 = 1;

            System.SByte a2 = 1;
            byte         b1 = 2;

            System.Byte b2 = 2;
            short       c1 = 3;

            System.Int16 c2 = 3;
            ushort       d1 = 4;

            System.UInt16 d2 = 4;
            int           e1 = 5;

            System.Int32 e2 = 5;
            uint         f1 = 6;

            System.UInt32 f2 = 6;
            long          g1 = 7;

            System.Int64 g2 = 7;
            ulong        h1 = 8;

            System.UInt64 h2 = 8;
            char          i1 = 'a';

            System.Char i2 = 'a';
            float       k1 = 10;

            System.Single k2 = 10;
            double        l1 = 11;

            System.Double l2 = 11;
            bool          m1 = true;

            System.Boolean m2 = true;
            decimal        n1 = 12;

            System.Decimal n2 = 12;
            object         o1 = new object { };

            System.Object o2 = new object { };
            string        p1 = "Hello";

            System.String p2 = "Hello";

            Console.WriteLine(a1.GetType() + "\n" + a2.GetType() + "\n" +
                              b1.GetType() + "\n" + b2.GetType() + "\n" +
                              c1.GetType() + "\n" + c2.GetType() + "\n" +
                              d1.GetType() + "\n" + d2.GetType() + "\n" +
                              e1.GetType() + "\n" + e2.GetType() + "\n" +
                              f1.GetType() + "\n" + f2.GetType() + "\n" +
                              g1.GetType() + "\n" + g2.GetType() + "\n" +
                              h1.GetType() + "\n" + h2.GetType() + "\n" +
                              i1.GetType() + "\n" + i2.GetType() + "\n" +
                              k1.GetType() + "\n" + k2.GetType() + "\n" +
                              l1.GetType() + "\n" + l2.GetType() + "\n" +
                              m1.GetType() + "\n" + m2.GetType() + "\n" +
                              n1.GetType() + "\n" + n2.GetType() + "\n" +
                              o1.GetType() + "\n" + o2.GetType() + "\n" +
                              p1.GetType() + "\n" + p2.GetType() + "\n");
        }
    void CheckOperators()
    {
        {
            /*
             * Section 6.21 Types and Operators
             */
            float a = 1.0f;
            float b = 3.0f;
            bool  c = a > b; // false
            bool  d = a < b; // true

            Debug.Log("c:" + c + " d:" + d);
        }
        {
            /*
             * adding strings together
             */
            string a = "hello, ";
            string b = "world.";
            string c = a + b;

            Debug.Log("c: " + c);
        }
        {
            /*
             * More things you can do with strings
             */
            string a = "hello, ";
            string b = "world.";
            bool   c = a == b;         // false
            bool   d = a == "world.";  // true
            bool   e = a == "hello, "; // false
            bool   f = a != b;         // true
            string g = a + b;          // hello, world.

            /*
             * Some things you can't do with strings
             */
            // string f = a - b;
            // string f = a * b;
            // string f = a / b;
            // bool g = a > b;
            // bool g = a < b;
        }
        {
            string a = "hello";
            switch (a)
            {
            case "hello":
                Debug.Log("a was hello");
                break;

            case "world":
                Debug.Log("a was world");
                break;

            default:
                break;
            }
        }
        {
            /*
             * Section 6.21.1 GetType()
             */
            int    a = 7;
            string b = "hello";
            bool   c = a.GetType() == b.GetType();
            Debug.Log("a and b are the same type? " + c);
            // "a and b are the same type? False

            Debug.Log("a is type: " + a.GetType());
            // a is type System.Int32
            Debug.Log("b is type: " + b.GetType());
            // b is type System.String
        }
        {
            int    a = 7;
            string b = "7";
            bool   c = a.ToString() == b;
            Debug.Log("a as a string is the same as b? " + c);
            // "a as a string is the same as b? True"
        }
        {
            int   a = 7;
            float b = 7.0f;
            bool  c = a == b;
            Debug.Log("int a == float b? " + c);
            // "int a == float b? True"
        }
        {
            /*
             * Section 6.21.2 More Type Casting
             */
            int   a = 7;
            float b = 7.9f;
            bool  c = a == b; // false
            /*   ↑   ↓    ↓                     */
            /*   │   │    └────┐                */
            /*   │ ┌─┴──┐    ┌─┴──┐             */
            /*   │ │ 7  │ == │7.9f│             */
            /*   │ └────┘ ↓  └────┘             */
            /*   │     ┌───────┐                */
            /*   └─────┤ False │                */
            /*         └───────┘                */
            bool d = a == (int)b;
            /*   ↑   ↓     ↓   ↓                */
            /*   │   │     │ ┌─┴──┐             */
            /*   │   │     │ │7.9f│             */
            /*   │   │     │ └─┬──┘             */
            /*   │   │     └─→(int) cast to int */
            /*   │   │         ↓                */
            /*   │ ┌─┴──┐    ┌─┴──┐             */
            /*   │ │ 7  │ == │ 7  │             */
            /*   │ └────┘ ↓  └────┘             */
            /*   │     ┌──────┐                 */
            /*   └─────┤ True │                 */
            /*         └──────┘                 */

            Debug.Log("c: " + c + " d: " + d);
            // c: False d: True
        }
        {
            int    a = 7;
            string b = "7";
            //bool c = a == (int)b;
            // Cannot convert type 'string' to 'int'
        }
        {
            GameObject a = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            GameObject b = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            bool       c = a == b;
            Debug.Log("GameObjects a == b? " + c);
            // GameObjects a == b? False

            int a_InstanceID = a.GetInstanceID();
            int b_InstanceID = b.GetInstanceID();
            Debug.Log("a_InstanceID: " + a_InstanceID);
            // a_InstanceID: -2500
            // though the number itself will change every time you run the game
            Debug.Log("b_InstanceID: " + b_InstanceID);
            // b_InstanceID: -2510
            // though the number itself will change every time you run the game
            Debug.Log("GameObjects a_InstanceID == b_InstanceID? " + c);
            // GameObjects a_InstanceID == b_InstanceID? False
        }
        {
            GameObject a = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            GameObject b;
            b = a;
            bool c = a == b;
            Debug.Log("GameObject a == b? " + c);
            // GameObject a == b? True
        }
        {
            GameObject gameObject = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            int        a          = gameObject.GetInstanceID();
            int        b;
            b = a;
            bool c = a == b;
            Debug.Log("InstanceIDs a == b? " + c);
            // InstanceIDs a == b? True
        }
        {
            /*
             * Can Types be equal?
             */
            GameObject a     = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            GameObject b     = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            Type       aType = a.GetType();
            Type       bType = b.GetType();
            bool       c     = aType == bType;
            Debug.Log("aType: " + aType + " bType: " + bType + " aType == bType? " + c);
            // aType: UnityEngine.GameObject bType: UnityEngine.GameObject aType == bType? True
        }
        {
            GameObject a = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            a.AddComponent <ZombieComponent>();
            // check if the GameObject a is a zombie by looking for the attached zombie component
            ZombieComponent component = a.GetComponent <ZombieComponent>();
            Type            b         = component.GetType();
            Type            c         = typeof(ZombieComponent);
            bool            d         = b == c;
            Debug.Log("b type: " + b + "c type: " + c + "b == c?" + d);
        }
        {
            System.Int32 a = 1;
            int          b = 3;
            bool         c = a.GetType() == b.GetType();
            Debug.Log("a == b? " + c);
            // "a == b? True

            System.Single d = 1.0f;
            float         e = 3.0f;
            bool          f = d.GetType() == e.GetType();
            Debug.Log("d == e? " + f);
            // "d == e? True
        }
        {
            /*
             * 6.21.3 Type Aliasing
             */
            MyOwnType a = 1;
            Debug.Log("a is a: " + a.GetType());
            // "a is a: System.Int16"
        }
        {
            /*
             * 6.21.4 Boxing and Unboxing
             */
            GameObject a = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            // remember, HumanWithStates : ZombieWithStates?
            ZombieWithStates b = a.AddComponent <HumanWithStates>();
            /*      ↑                                  ↑        */
            /*      └────────────────┬─────────────────┘        */
            /*                ┌──────┴─────────────┐            */
            /*                │types don't match   │            */
            /*                │but HumanWithStates │            */
            /*                │inherits from       │            */
            /*                │ZombieWithStates    │            */
            /*                └────────────────────┘            */

            GameObject    c = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            MonoBehaviour d = c.AddComponent <ZombieWithStates>();
            /*      ↑                                  ↑        */
            /*      └────────────────┬─────────────────┘        */
            /*                ┌──────┴─────────────┐            */
            /*                │types don't match   │            */
            /*                │either but          │            */
            /*                │ZombieWithStates    │            */
            /*                │inherits from       │            */
            /*                │MonoBehaviour       │            */
            /*                └────────────────────┘            */

            object e = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            /*  ↑           ↑                                   */
            /*  └─────┬─────┘                                   */
            /* ┌──────┴─────────────┐                           */
            /* │GameObject inherits │                           */
            /* │from object         │                           */
            /* │but every class in  │                           */
            /* │C# inherits from    │                           */
            /* │object!             │                           */
            /* └────────────────────┘                           */
            object f = 1;
            object g = 1.0f;
            object h = new object[] { 1, 1.0f, e, d, c, b, a };
            Debug.Log("what is h really? " + h);
            // what is h really? System.Object[]
            object[] objArray = h as object[];
            foreach (object o in objArray)
            {
                if (o is GameObject)
                {
                    Debug.Log("got a GameObject!");
                }
            }
            // got a GameObject!
            // got a GameObject!
            // got a GameObject!

            UnityEngine.Object[] allObjectsInTheScene = FindObjectsOfType <UnityEngine.Object>();
            foreach (UnityEngine.Object o in allObjectsInTheScene)
            {
                Debug.Log("Object: " + o);
            }
            // all kinds of things!
        }
    }
Esempio n. 34
0
        static void Main()
        {
            /*
             * prefix s - simple type, primitive type, built in type, value type
             * prefix f - .NET Framework type
             *
             * Numeric Types
             */

            // signed 8 bit integer
            sbyte sByte = -128;

            System.SByte fByte = 127;

            // unsigned 8 bit integer
            byte sUnByte = 0;

            System.Byte fUnByte = 255;

            // signed 16 bit integer
            short sShort = -32768;

            System.Int16 fShort = 32767;

            // unsigned 16 bit integer
            ushort sUnShort = 0;

            System.UInt16 fUnShort = 65535;

            // signed 32 bit integer
            int sInt = -2147483648;

            System.Int32 fInt = 2_147_483_647;

            // unsigned 32 bit integer
            uint sUnInt = 0;

            System.UInt32 fUnInt = 4_294_967_295;

            // signed 64 bit integer
            long sLong = -9_223_372_036_854_775_808;

            System.Int64 fLong = 0x7FFFFFFFFFFFFFFF;

            // unsigned 64 bit integer
            ulong sUnLong = 0;

            System.UInt64 fUnLong = System.UInt64.MaxValue;

            // float 32 bit floating-point value (to initialize float use suffix 'f' or 'F')
            float sFloat = -3.5F;

            System.Single fFloat = 3.5f;

            // double 64 bit floating-point value
            double sDouble = System.Double.MinValue;

            System.Double fDouble = System.Double.MaxValue;

            // decimal 128 bit floating-point value (financial calculations)(use suffix m for real numbers)
            decimal sDecimal = 300.5m;

            System.Decimal fDecimal = 300;

            // character data type
            char sChar = 'a';

            System.Char fChar = 'z';

            // boolean type
            bool trueValue  = true;
            bool falseValue = false;    // default value for bool type

            // write to console
            Console.WriteLine("Type: {0}, Value: {1}", sByte.GetType(), sByte);
            Console.WriteLine("Type: {0}, Value: {1}", fByte.GetType(), fByte);
            Console.WriteLine("Type: {0}, Value: {1}", sUnByte.GetType(), sUnByte);
            Console.WriteLine("Type: {0}, Value: {1}", fUnByte.GetType(), fUnByte);
            Console.WriteLine("Type: {0}, Value: {1}", sShort.GetType(), sShort);
            Console.WriteLine("Type: {0}, Value: {1}", fShort.GetType(), fShort);
            Console.WriteLine("Type: {0}, Value: {1}", sUnShort.GetType(), sUnShort);
            Console.WriteLine("Type: {0}, Value: {1}", fUnShort.GetType(), fUnShort);
            Console.WriteLine("Type: {0}, Value: {1}", sInt.GetType(), sInt);
            Console.WriteLine("Type: {0}, Value: {1}", fInt.GetType(), fInt);
            Console.WriteLine("Type: {0}, Value: {1}", sUnInt.GetType(), sUnInt);
            Console.WriteLine("Type: {0}, Value: {1}", fUnInt.GetType(), fUnInt);
            Console.WriteLine("Type: {0}, Value: {1}", sLong.GetType(), sLong);
            Console.WriteLine("Type: {0}, Value: {1}", fLong.GetType(), fLong);
            Console.WriteLine("Type: {0}, Value: {1}", sUnLong.GetType(), sUnLong);
            Console.WriteLine("Type: {0}, Value: {1}", fUnLong.GetType(), fUnLong);
            Console.WriteLine("Type: {0}, Value: {1}", sFloat.GetType(), sFloat);
            Console.WriteLine("Type: {0}, Value: {1}", fFloat.GetType(), fFloat);
            Console.WriteLine("Type: {0}, Value: {1}", sDouble.GetType(), sDouble);
            Console.WriteLine("Type: {0}, Value: {1}", fDouble.GetType(), fDouble);
            Console.WriteLine("Type: {0}, Value: {1}", sDecimal.GetType(), sDecimal);
            Console.WriteLine("Type: {0}, Value: {1}", fDecimal.GetType(), fDecimal);
            Console.WriteLine("Type: {0}, Value: {1}", sChar.GetType(), sChar);
            Console.WriteLine("Type: {0}, Value: {1}", fChar.GetType(), fChar);
            Console.WriteLine("Type: {0}, Value: {1}", trueValue.GetType(), trueValue);
            Console.WriteLine("Type: {0}, Value: {1}", falseValue.GetType(), falseValue);

            // wait for user input to close the window
            Console.WriteLine();
            Console.Write("Press any key to continue...");
            Console.ReadKey(true);
        }