public static void showBool() { bool a = true; Boolean b = true; Console.WriteLine(a.GetType()); Console.WriteLine(b.GetType()); Console.WriteLine(a == b); }
public void TestBoolean() { FileStream stream = new FileStream("Prova.bin", System.IO.FileMode.Create); CompactFormatter CFormatter = new CompactFormatter(); Interfaces.IStreamParser str = new JunkStreamParser(); CFormatter.RegisterStreamParser(str); long start = DateTime.Now.Ticks; Boolean s = true; Console.WriteLine( "Serializing and Deserializing {0} instances of type {1}", max, s.GetType().ToString() ); for (int i = 0; i < max; i++) { CFormatter.Serialize(stream, s); //Console.WriteLine("Serialized {0}",s); s = !s; } stream.Flush(); stream.Close(); stream = new FileStream("Prova.bin", System.IO.FileMode.Open); CompactFormatter CFormatter2 = new CompactFormatter(); str = new JunkStreamParser(); CFormatter2.RegisterStreamParser(str); Boolean[] temp = new Boolean[max]; for (int i = 0; i < max; i++) { temp[i] = (Boolean)CFormatter2.Deserialize(stream); } stream.Close(); long stop = DateTime.Now.Ticks; long ts = stop - start; Console.WriteLine("Elapsed Time:{0},{1},{2}", ts, start, stop); s = true; for (int i = 0; i < max; i++) { //Console.WriteLine("Deserialized {0}",temp[i]); Assert.AreEqual(temp[i], s); s = !s; } }
static void Main(string[] args) { int variableInt = 5; long variableLong = 76876; float variableFloat = 5.78f; double variableDouble = 687.9; decimal variableDecimal = 545.777m; char variableChar = 'A'; string variableString = "Hola"; Boolean variableBoolean = true; PrintVariable(nameof(variableInt), variableInt, variableInt.GetType()); PrintVariable(nameof(variableLong), variableLong, variableLong.GetType()); PrintVariable(nameof(variableFloat), variableFloat, variableFloat.GetType()); PrintVariable(nameof(variableDouble), variableDouble, variableDouble.GetType()); PrintVariable(nameof(variableDecimal), variableDecimal, variableDecimal.GetType()); PrintVariable(nameof(variableChar), variableChar, variableChar.GetType()); PrintVariable(nameof(variableString), variableString, variableString.GetType()); PrintVariable(nameof(variableBoolean), variableBoolean, variableBoolean.GetType()); int num1 = 36, num2 = 4; if (num1 == num2) { OperacionesComparacion("son iguales"); } else { OperacionesComparacion("No son iguales"); } if (num1 < num2) { OperacionesComparacion(num2 + " es mayor"); } else { OperacionesComparacion(num1 + " es mayor"); } OperacionesComparacion("suma: " + (num1 + num2)); OperacionesComparacion("resta: " + (num1 - num2)); OperacionesComparacion("multiplicación: " + (num1 * num2)); OperacionesComparacion("división: " + (num1 / num2)); OperacionesComparacion("potencia: " + (num1 ^ num2)); OperacionesComparacion("raiz cuadrada de " + num1 + " es: " + Math.Sqrt(num1)); OperacionesComparacion("raiz cuadrada de " + num2 + " es: " + Math.Sqrt(num2)); }
public static void GetInstanceInformation() { String dataSource = Utility.DBConnection.DataSource; Int32 packetSize = Utility.DBConnection.PacketSize; String serverVersion = Utility.DBConnection.ServerVersion; Boolean statisticsEnabled = Utility.DBConnection.StatisticsEnabled; String workstationId = Utility.DBConnection.WorkstationId; instanceInformation.Columns.Clear(); instanceInformation.Columns.Add("dataSource", dataSource.GetType()); instanceInformation.Columns.Add("packetSize", packetSize.GetType()); instanceInformation.Columns.Add("serverVersion", serverVersion.GetType()); instanceInformation.Columns.Add("statisticsEnabled", statisticsEnabled.GetType()); instanceInformation.Columns.Add("workstationId", workstationId.GetType()); instanceInformation.Rows.Add(dataSource, packetSize, serverVersion, statisticsEnabled, workstationId); //Utility.PrintDatatable(instanceInformation); }
public void TestBoolean() { FileStream stream = new FileStream("Prova.bin", System.IO.FileMode.Create); CompactFormatter CFormatter = new CompactFormatter(); long start = DateTime.Now.Ticks; Boolean[] s = new Boolean[max]; Console.WriteLine( "Serializing and Deserializing an array of type {1} composed by {0} elements", max, s.GetType().ToString() ); s[0] = true; for (int i = 1; i < max; i++) { s[i] = !s[i - 1]; } CFormatter.Serialize(stream, s); stream.Flush(); stream.Close(); stream = new FileStream("Prova.bin", System.IO.FileMode.Open); CompactFormatter CFormatter2 = new CompactFormatter(); Boolean[] temp = new Boolean[max]; temp = (Boolean[])CFormatter2.Deserialize(stream); stream.Close(); long stop = DateTime.Now.Ticks; long ts = stop - start; Console.WriteLine("Elapsed Time:{0},{1},{2}", ts, start, stop); Boolean s2 = true; for (int i = 0; i < max; i++) { Assert.AreEqual(temp[i], s2); s2 = !s2; } }
static void Main(string[] args) { bool isTrue = true; Boolean isFalse = false; short sh1 = 5; Int16 sh2 = 6; int i1 = 33; Int32 i2 = 22; long l1 = 4444; Int64 l2 = 5555; byte b1 = 12; Byte b2 = 13; float f1 = 66.66f; Single f2 = 77.77f; double d1 = 888.888; Double d2 = 878.788; decimal dec1 = 99999999.99M; Decimal dec2 = 9888999.98M; object o1 = new object[1, 2, 3]; Object o2 = new Object[3, 2, 1]; char ch1 = 'A'; Char ch2 = 'B'; string s1 = "Hello there!"; String s2 = "General Kenobi!"; Console.WriteLine($"Bool:\n C#: {isTrue.GetType()}\n CLR: {isFalse.GetType()}"); Console.WriteLine($"Short:\n C#: {sh1.GetType()}\n CLR: {sh2.GetType()}"); Console.WriteLine($"Int:\n C#: {i1.GetType()}\n CLR: {i2.GetType()}"); Console.WriteLine($"Long:\n C#: {l1.GetType()}\n CLR: {l2.GetType()}"); Console.WriteLine($"Byte:\n C#: {b1.GetType()}\n CLR: {b2.GetType()}"); Console.WriteLine($"Float:\n C#: {f1.GetType()}\n CLR: {f2.GetType()}"); Console.WriteLine($"Double:\n C#: {d1.GetType()}\n CLR: {d2.GetType()}"); Console.WriteLine($"Decimal:\n C#: {dec1.GetType()}\n CLR: {dec2.GetType()}"); Console.WriteLine($"Object (array):\n C#: {o1.GetType()}\n CLR: {o2.GetType()}"); Console.WriteLine($"Char:\n C#: {ch1.GetType()}\n CLR: {ch2.GetType()}"); Console.WriteLine($"String:\n C#: {s1.GetType()}\n CLR: {s2.GetType()}"); Console.ReadKey(); }
public bool PosTest <T>(int id, T curValue, Boolean expValue) { bool retVal = true; Boolean newValue; IFormatProvider fp; TestLibrary.TestFramework.BeginScenario("PosTest" + id + ": Convert.ToBoolean(...) (curValue:" + typeof(T) + " " + curValue + " newType:" + expValue.GetType() + ")"); try { newValue = Convert.ToBoolean(curValue); if (!newValue.Equals(expValue)) { TestLibrary.TestFramework.LogError("000", "Value mismatch: Expected(" + expValue + ") Actual(" + newValue + ")"); retVal = false; } fp = null; newValue = Convert.ToBoolean(curValue, fp); if (!newValue.Equals(expValue)) { TestLibrary.TestFramework.LogError("001", "Value mismatch: Expected(" + expValue + ") Actual(" + newValue + ")"); retVal = false; } } catch (Exception e) { TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e); retVal = false; } return(retVal); }
static void Main(string[] args) { bool a1 = true; Boolean a2 = true; byte b1 = 1; Byte b2 = 2; char c1 = '%'; Char c2 = '&'; decimal d1 = 10; Decimal d2 = 10; sbyte sb1 = 1; SByte sb2 = -15; float fl1 = 4.5f; Single fl2 = 4.6f; double db1 = 55.55; Double db2 = 55.66; short sh1 = 1; Int16 sh2 = 1; ushort ush1 = 10; UInt16 ush2 = 10; int i1 = 5; Int32 i2 = 5; uint ui1 = 5000; UInt32 ui2 = 5000; long l1 = 155; Int64 l2 = 156; ulong ul1 = 500; UInt64 ul2 = 501; object ob1 = 500; Object ob2 = 500; string str1 = "stroka"; String str2 = "stroka2"; Console.WriteLine("Variable type: " + a1.GetType()); Console.WriteLine("Variable type: " + a2.GetType()); Console.WriteLine("Variable type: " + b1.GetType()); Console.WriteLine("Variable type: " + b2.GetType()); Console.WriteLine("Variable type: " + c1.GetType()); Console.WriteLine("Variable type: " + c2.GetType()); Console.WriteLine("Variable type: " + d1.GetType()); Console.WriteLine("Variable type: " + d2.GetType()); Console.WriteLine("Variable type: " + sb1.GetType()); Console.WriteLine("Variable type: " + sb2.GetType()); Console.WriteLine("Variable type: " + fl1.GetType()); Console.WriteLine("Variable type: " + fl2.GetType()); Console.WriteLine("Variable type: " + db1.GetType()); Console.WriteLine("Variable type: " + db2.GetType()); Console.WriteLine("Variable type: " + sh1.GetType()); Console.WriteLine("Variable type: " + sh2.GetType()); Console.WriteLine("Variable type: " + ush1.GetType()); Console.WriteLine("Variable type: " + ush2.GetType()); Console.WriteLine("Variable type: " + i1.GetType()); Console.WriteLine("Variable type: " + i2.GetType()); Console.WriteLine("Variable type: " + ui1.GetType()); Console.WriteLine("Variable type: " + ui2.GetType()); Console.WriteLine("Variable type: " + l1.GetType()); Console.WriteLine("Variable type: " + l2.GetType()); Console.WriteLine("Variable type: " + ul1.GetType()); Console.WriteLine("Variable type: " + ul2.GetType()); Console.WriteLine("Variable type: " + ob1.GetType()); Console.WriteLine("Variable type: " + ob2.GetType()); Console.WriteLine("Variable type: " + str1.GetType()); Console.WriteLine("Variable type: " + str2.GetType()); Console.ReadKey(); }
public void Convert_PrimitiveDatatypeToString_Test() { { Boolean t1 = true; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("True"); } { Byte t1 = 5; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("5"); } { SByte t1 = 5; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("5"); } { Int16 t1 = 5; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("5"); } { UInt16 t1 = 5; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("5"); } { Int32 t1 = 5; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("5"); } { UInt32 t1 = 5; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("5"); } { Int64 t1 = 5; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("5"); } { UInt64 t1 = 5; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("5"); } { Char t1 = '5'; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("5"); } { Double t1 = 1.79; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("1.79"); } { Single t1 = 1.79f; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("1.79"); } { Decimal t1 = 1.79M; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("1.79"); } { string t1 = null; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", typeof(string), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().BeNull(); } { string t1 = ""; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be(""); } { string t1 = "foo"; var SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null)); SPV.PropertyValue = t1; SPV.SerializedValue.Should().Be("foo"); } }
public static Type ToType(CIMType cimtype, bool bIsArray, Property prop) { Type t = null; switch (cimtype) { case (CIMType.Boolean): { if (bIsArray) { Boolean[] ar = new Boolean[0]; t = ar.GetType(); } else { t = typeof(Boolean); } } break; case (CIMType.Char16): { if (bIsArray) { Char[] ar = new Char[0]; t = ar.GetType(); } else { t = typeof(Char); } } break; case (CIMType.DateTime): { if (WmiHelper.IsInterval(prop)) { if (bIsArray) { TimeSpan[] ar = new TimeSpan[0]; t = ar.GetType(); } else { t = typeof(TimeSpan); } } else { if (bIsArray) { DateTime[] ar = new DateTime[0]; t = ar.GetType(); } else { t = typeof(DateTime); } } } break; case (CIMType.Object): { if (bIsArray) { WMIObjectComponent[] ar = new WMIObjectComponent[0]; t = ar.GetType(); } else { t = typeof(WMIObjectComponent); } } break; case (CIMType.Real32): { if (bIsArray) { Single[] ar = new Single[0]; t = ar.GetType(); } else { t = typeof(Single); } } break; case (CIMType.Real64): { if (bIsArray) { Double[] ar = new Double[0]; t = ar.GetType(); } else { t = typeof(Double); } } break; case (CIMType.Reference): { if (bIsArray) { String[] ar = new String[0]; t = ar.GetType(); } else { t = typeof(String); } } break; case (CIMType.Sint16): { if (bIsArray) { Int16[] ar = new Int16[0]; t = ar.GetType(); } else { t = typeof(Int16); } } break; case (CIMType.Sint32): { if (bIsArray) { Int32[] ar = new Int32[0]; t = ar.GetType(); } else { t = typeof(Int32); } } break; case (CIMType.Sint64): { if (bIsArray) { Int64[] ar = new Int64[0]; t = ar.GetType(); } else { t = typeof(Int64); } } break; case (CIMType.Sint8): { if (bIsArray) { SByte[] ar = new SByte[0]; t = ar.GetType(); } else { t = typeof(SByte); } } break; case (CIMType.String): { if (bIsArray) { String[] ar = new String[0]; t = ar.GetType(); //return typeof(System.Collections.ArrayList); } else { t = typeof(String); } } break; case (CIMType.Uint16): { if (bIsArray) { UInt16[] ar = new UInt16[0]; t = ar.GetType(); } else { t = typeof(UInt16); } } break; case (CIMType.Uint32): { if (bIsArray) { UInt32[] ar = new UInt32[0]; t = ar.GetType(); } else { t = typeof(UInt32); } } break; case (CIMType.Uint64): { if (bIsArray) { UInt64[] ar = new UInt64[0]; t = ar.GetType(); } else { t = typeof(UInt64); } } break; case (CIMType.Uint8): { if (bIsArray) { Byte[] ar = new Byte[0]; t = ar.GetType(); } else { t = typeof(Byte); } } break; default: { if (bIsArray) { Object[] ar = new Object[0]; t = ar.GetType(); } else { t = typeof(Object); } } } return(t); }
public void TestGetType() { Boolean t = true, f = false; Assert.AreEqual(true, Object.ReferenceEquals(t.GetType(), f.GetType()), "GetType failed"); }
static void Main(string[] args) { int int1 = 3; Int32 int2 = 4; Console.WriteLine(int1.GetType()); Console.WriteLine(int2.GetType()); Console.WriteLine(); bool bool1 = true; Boolean bool2 = false; Console.WriteLine(bool1.GetType()); Console.WriteLine(bool2.GetType()); Console.WriteLine(); byte byte1 = 1; Byte byte2 = 2; Console.WriteLine(byte1.GetType()); Console.WriteLine(byte2.GetType()); Console.WriteLine(); sbyte sbyte1 = 1; SByte sbyte2 = 2; Console.WriteLine(sbyte1.GetType()); Console.WriteLine(sbyte2.GetType()); Console.WriteLine(); short short1 = 1; Int16 short2 = 2; Console.WriteLine(short1.GetType()); Console.WriteLine(short2.GetType()); Console.WriteLine(); ushort ushort1 = 1; UInt16 ushort2 = 2; Console.WriteLine(ushort1.GetType()); Console.WriteLine(ushort2.GetType()); Console.WriteLine(); uint uint1 = 1; UInt32 uint2 = 2; Console.WriteLine(uint1.GetType()); Console.WriteLine(uint2.GetType()); Console.WriteLine(); long long1 = 1; Int64 long2 = 2; Console.WriteLine(long1.GetType()); Console.WriteLine(long2.GetType()); Console.WriteLine(); ulong ulong1 = 1; UInt64 ulong2 = 2; Console.WriteLine(ulong1.GetType()); Console.WriteLine(ulong2.GetType()); Console.WriteLine(); float float1 = 1.1f; Single float2 = 2.2f; Console.WriteLine(float1.GetType()); Console.WriteLine(float2.GetType()); Console.WriteLine(); double double1 = 1.1; Double double2 = 2.2; Console.WriteLine(double1.GetType()); Console.WriteLine(double2.GetType()); Console.WriteLine(); decimal decimal1 = 1.1m; Decimal decimal2 = 2.2m; Console.WriteLine(decimal1.GetType()); Console.WriteLine(decimal2.GetType()); Console.WriteLine(); char char1 = 'a'; Char char2 = 'b'; Console.WriteLine(char1.GetType()); Console.WriteLine(char2.GetType()); Console.WriteLine(); string string1 = "AAA"; String string2 = "BBB"; Console.WriteLine(string1.GetType()); Console.WriteLine(string2.GetType()); Console.WriteLine(); object object1 = new object(); Object object2 = new Object(); Console.WriteLine(object1.GetType()); Console.WriteLine(object2.GetType()); Console.WriteLine(); //explicit type conversion int1 = 42; long1 = int1; // conversion int to long short1 = 3; float1 = short1; //conversion shot to float string1 = "Test"; object1 = string1; //conversion string to object //implicit type conversion int2 = (int)long1; // conversion long to int short2 = (short)float1; //conversion float to short string2 = (string)object1; //conversion object to string decimal1 = 23.123m; object2 = decimal1; //boxing decimal2 = (decimal)object2; //unboxing Console.ReadKey(); }
public void Save(String PropertyName, Boolean Value) { _GameSaver.CreateChildElement(_Element, PropertyName, Value.GetType(), Value.ToString(_GameSaver.CultureInfo)); }
static void Main(string[] args) { //числовые (целочисленные) byte bit1 = 1; Byte bit2 = 1; Console.WriteLine(bit1.GetType()); Console.WriteLine(bit2.GetType()); sbyte bit3 = 2; SByte bit4 = 2; Console.WriteLine(bit3.GetType()); Console.WriteLine(bit4.GetType()); short shot1 = 3; Int16 shot2 = 3; Console.WriteLine(shot1.GetType()); Console.WriteLine(shot2.GetType()); ushort shot3 = 4; UInt16 shot4 = 4; Console.WriteLine(shot3.GetType()); Console.WriteLine(shot4.GetType()); int i1 = 5; Int32 i2 = 5; Console.WriteLine(i1.GetType()); Console.WriteLine(i2.GetType()); uint i3 = 6; UInt32 i4 = 6; Console.WriteLine(i3.GetType()); Console.WriteLine(i4.GetType()); long l1 = 7; UInt64 l2 = 7; Console.WriteLine(l1.GetType()); Console.WriteLine(l2.GetType()); ulong l3 = 8; UInt64 l4 = 8; Console.WriteLine(l3.GetType()); Console.WriteLine(l4.GetType()); //числовые (c плавающей точкой) float flt1 = 9f; Single flt2 = 9f; Console.WriteLine(flt1.GetType()); Console.WriteLine(flt2.GetType()); double d1 = 10d; Double d2 = 10d; Console.WriteLine(d1.GetType()); Console.WriteLine(d2.GetType()); decimal dcm1 = 11m; Decimal dcm2 = 11m; Console.WriteLine(dcm1.GetType()); Console.WriteLine(dcm2.GetType()); //Символьные типы char chr1 = 'a'; Char chr2 = 'b'; Console.WriteLine(chr1.GetType()); Console.WriteLine(chr2.GetType()); string str1 = "word"; string str2 = "world"; Console.WriteLine(str1.GetType()); Console.WriteLine(str2.GetType()); //Логический тип bool bl1 = true; Boolean bl2 = false; Console.WriteLine(bl1.GetType()); Console.WriteLine(bl2.GetType()); //Особые типы object obj1 = i3; Object obj2 = str2; Console.WriteLine(obj1.GetType()); Console.WriteLine(obj2.GetType()); dynamic dnmc = "stringValue"; Console.WriteLine(dnmc.GetType()); Console.ReadKey(); }