static void Main(string[] args) { // Display title. Console.WriteLine("ASP.NET Validators"); Console.WriteLine(); // Create Long and Validator. Int64 testLong = 17592186044416; Int64 minLongVal = 1099511627776; Int64 maxLongVal = 281474976710656; LongValidator myLongValidator = new LongValidator(minLongVal, maxLongVal, false); // Determine if the object to validate can be validated. Console.WriteLine("CanValidate: {0}", myLongValidator.CanValidate(testLong.GetType())); try { // Attempt validation. myLongValidator.Validate(testLong); Console.WriteLine("Validated."); } catch (ArgumentException e) { // Validation failed. Console.WriteLine("Error: {0}", e.Message.ToString()); } // Display and wait Console.ReadLine(); }
public static void showInt() { short a = 0; ushort b = 0; int c = 0; uint d = 0; long e = 0L; ulong f = 0L; Int16 g = 0; Int32 h = 0; Int64 i = 0; UInt16 j = 0; UInt32 k = 0; UInt64 l = 0; Console.WriteLine(a.GetType()); Console.WriteLine(b.GetType()); Console.WriteLine(c.GetType()); Console.WriteLine(d.GetType()); Console.WriteLine(e.GetType()); Console.WriteLine(f.GetType()); Console.WriteLine(g.GetType()); Console.WriteLine(h.GetType()); Console.WriteLine(i.GetType()); Console.WriteLine(j.GetType()); Console.WriteLine(k.GetType()); Console.WriteLine(l.GetType()); }
public static void Main() { try { // <Snippet1> Int64 myVariable1 = 80; Int64 myVariable2 = 80; // Get and display the declaring type. Console.WriteLine("\nType of 'myVariable1' is '{0}' and" + " value is :{1}", myVariable1.GetType(), myVariable1); Console.WriteLine("Type of 'myVariable2' is '{0}' and" + " value is :{1}", myVariable2.GetType(), myVariable2); // Compare 'myVariable1' instance with 'myVariable2' Object. if (myVariable1.Equals(myVariable2)) { Console.WriteLine("\nStructures 'myVariable1' and " + "'myVariable2' are equal"); } else { Console.WriteLine("\nStructures 'myVariable1' and " + "'myVariable2' are not equal"); } // </Snippet1> } catch (Exception e) { Console.WriteLine("Exception :{0}", e.Message); } }
static void Main(string[] args) { int num = 0; Int32 num1 = 0; byte num2 = 0; System.Byte num3 = 0; char s = '0'; System.Char s1 = '0'; long num4 = 0; Int64 num5 = 0; object o = 0; string str = "0"; Console.WriteLine(num.GetType().ToString()); Console.WriteLine(num1.GetType().ToString()); Console.WriteLine(num2.GetType().ToString()); Console.WriteLine(num3.GetType().ToString()); Console.WriteLine(s.GetType().ToString()); Console.WriteLine(s1.GetType().ToString()); Console.WriteLine(num4.GetType().ToString()); Console.WriteLine(num5.GetType().ToString()); Console.WriteLine(o.GetType().ToString()); Console.WriteLine(str.GetType().ToString()); Console.ReadKey(); }
Int64 compareInt64(Int64 b, Int64 b2) { if (b == b2) { return(b); } throw new IllegalStateException("Not got expected value for type: " + b2.GetType().ToString()); }
public void TestGetInt64() { Int64 l = 0x1234567812345678; Binary bin = Serialize(l); IPofValue root = PofValueParser.Parse(bin, GetPofContext()); Int64 pv = root.GetInt64(); Assert.IsInstanceOf(l.GetType(), pv); Assert.AreEqual(l, pv); }
public void TestInt64() { Property myProperty = new Property(new Uri("ex:myProperty")); Resource r = new Resource(new Uri("ex:myResource")); Int64 val = 126; r.AddProperty(myProperty, val); object res = r.ListValues(myProperty).First(); Assert.AreEqual(val.GetType(), res.GetType()); Assert.AreEqual(val, res); r.RemoveProperty(myProperty, val); }
/* Oefening 8 * * 2. Wat gebeurt er als u een woord invoert in plaats van een getal? * Dan krijg je een exception * * 4. Is het probleem hiermee opgelost? * Nee omdat er nu een ander soort exception is. * * 6. Je zou kunnen maken dat het programma aangeeft dat het niet gelukt is. ********************************************************************/ // Oefening 9 static void VanGrootNaarKlein() { Int64 grootGetal = 4294967295528; int kleinGetal = (int)grootGetal; try { kleinGetal = Convert.ToInt32(grootGetal); Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.", grootGetal.GetType().Name, grootGetal, kleinGetal.GetType().Name, kleinGetal); } catch (OverflowException) { Console.WriteLine("{0} is outside the range of the Int32 type.", grootGetal); } catch (FormatException) { Console.WriteLine("The {0} value '{1}' is not in a recognizable format.", grootGetal.GetType().Name, grootGetal); Console.WriteLine("Het Int64 bakje is: {0} En het Int32 bakje is: {1}", grootGetal, kleinGetal); } }
public void TestInt64() { FileStream stream = new FileStream("Prova.bin", System.IO.FileMode.Create); CompactFormatter CFormatter = new CompactFormatter(); long start = DateTime.Now.Ticks; Int64[] s = new Int64[max]; s[0] = 0; Console.WriteLine( "Serializing and Deserializing an array of type {1} composed by {0} elements", max, s.GetType().ToString() ); for (int i = 1; i < max; i++) { //Console.WriteLine("Serialized {0}",s); s[i] = s[i - 1] + 1; } CFormatter.Serialize(stream, s); stream.Flush(); stream.Close(); stream = new FileStream("Prova.bin", System.IO.FileMode.Open); CompactFormatter CFormatter2 = new CompactFormatter(); Int64[] temp = new Int64[max]; //for(int i = 0; i<max; i++) //{ temp = (Int64[])CFormatter2.Deserialize(stream); //} stream.Close(); long stop = DateTime.Now.Ticks; long ts = stop - start; Console.WriteLine("Elapsed Time:{0},{1},{2}", ts, start, stop); Int64 s2 = 0; for (int i = 0; i < max; i++) { //Console.WriteLine("Deserialized {0}",temp[i]); Assert.AreEqual(temp[i], s2); s2++; } }
public static void Main() { Double[] values = { Double.MinValue, -67890.1234, -12345.6789, 12345.6789, 67890.1234, Double.MaxValue, Double.NaN, Double.PositiveInfinity, Double.NegativeInfinity }; checked { foreach (var value in values) { try { Int64 lValue = (long)value; Console.WriteLine("{0} ({1}) --> {2} (0x{2:X16}) ({3})", value, value.GetType().Name, lValue, lValue.GetType().Name); } catch (OverflowException) { Console.WriteLine("Unable to convert {0} to Int64.", value); } try { UInt64 ulValue = (ulong)value; Console.WriteLine("{0} ({1}) --> {2} (0x{2:X16}) ({3})", value, value.GetType().Name, ulValue, ulValue.GetType().Name); } catch (OverflowException) { Console.WriteLine("Unable to convert {0} to UInt64.", value); } try { Decimal dValue = (decimal)value; Console.WriteLine("{0} ({1}) --> {2} ({3})", value, value.GetType().Name, dValue, dValue.GetType().Name); } catch (OverflowException) { Console.WriteLine("Unable to convert {0} to Decimal.", value); } try { Single sValue = (float)value; Console.WriteLine("{0} ({1}) --> {2} ({3})", value, value.GetType().Name, sValue, sValue.GetType().Name); } catch (OverflowException) { Console.WriteLine("Unable to convert {0} to Single.", value); } Console.WriteLine(); } } }
public void TestInt64() { FileStream stream = new FileStream("Prova.bin", System.IO.FileMode.Create); CompactFormatter CFormatter = new CompactFormatter(); long start = DateTime.Now.Ticks; Int64 s = 0; 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++; } stream.Flush(); stream.Close(); stream = new FileStream("Prova.bin", System.IO.FileMode.Open); CompactFormatter CFormatter2 = new CompactFormatter(); Int64[] temp = new Int64[max]; for (int i = 0; i < max; i++) { temp[i] = (Int64)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 = 0; for (int i = 0; i < max; i++) { //Console.WriteLine("Deserialized {0}",temp[i]); Assert.AreEqual(temp[i], s); s++; } }
static void Main(string[] args) { int i = 0; Int16 entero16 = 0; Int32 entero32 = 0; Int64 entero64 = 0; char caracter = (char)65; byte octeto = 0; //Mostrar los distintos tipos Console.WriteLine(" TIPOS DE DATOS "); Console.WriteLine("------------------------"); Console.WriteLine(" Entero: {0}", i.GetType()); Console.WriteLine(" Caracter: {0}", caracter.GetType()); Console.WriteLine(" Octeto: {0}", octeto.GetType()); Console.WriteLine(" Entero64: {0}", entero64.GetType()); //Mostrar el rango máximo y mínimo de cada tipo. Console.WriteLine("Minimo {0}, máximo {1}", char.MinValue, char.MaxValue); }
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(); }
static void Main() { sbyte var1 = 127; Int64 var2 = 50; ushort var3 = 333; double var4 = 2.2814; if (var1.GetType() == typeof(SByte)) { Console.WriteLine("var1 type ok."); } if (var2.GetType() == typeof(Int64)) { Console.WriteLine("var2 type ok"); } if (var3.GetType() == typeof(UInt16)) { Console.WriteLine("var2 type ok"); } if (var4.GetType() == typeof(Double)) { Console.WriteLine("var2 type ok"); } }
static void Main(string[] args) { Debug.WriteLine("hi"); int i = 1234567890; Int16 j = 12345; Int32 k = 1234567890; Int64 l = 1234567890123456789; float f = 1.23456789023456789F; // F mandatory double d = 1.23456789023456789D; // D optional Console.WriteLine(double.MaxValue); Console.WriteLine(double.MinValue); decimal dd = 1.2345678902345678901234M; // M optional Console.WriteLine("Integers by default are 32 bits long."); Console.WriteLine("Example of int is {0}", i); Console.WriteLine("Example of {0} is {1}", j.GetType(), j); Console.WriteLine("Example of {0} is {1}", k.GetType(), k); Console.WriteLine("Example of {0} is {1}", l.GetType(), l); Console.WriteLine("Float f is 32 bits long. Example is " + f + ". Note that floats have 7 digit precision"); Console.WriteLine("Double d is 64 bits long. Example is " + d + ". Note that doubles have 15 digit precision"); Console.WriteLine("Decimal dd is 128 bit long. Example is " + dd); long lg = 1234567890123456789; Console.WriteLine("Long lg is " + lg); bool b = true; Console.WriteLine("Boolean b is " + b); string x = "h"; char c = Convert.ToChar(x); Console.WriteLine("Char c is " + c); Console.WriteLine(); Console.WriteLine(); Char char01 = 'a'; Console.WriteLine(char01); Console.WriteLine("== Char From ASCII number =="); Char char02 = (char)121; Console.WriteLine(char02); Console.WriteLine(); Console.WriteLine("== Char Array From Letters =="); Char[] charArray01 = { 'a', 'b', 'c' }; foreach (char charItem in charArray01) { Console.WriteLine(charItem.ToString()); } Char[] charArray02 = new char[10]; // blank char array Console.WriteLine(); Console.WriteLine("== Char Array From Letters =="); Char[] charArray03 = new char[] { 'a', 'b', 'c' }; foreach (char charItem in charArray02) { Console.WriteLine(charItem.ToString()); } Console.WriteLine(); Console.WriteLine("== Char Array From Numbers =="); char[] charArray04 = new char[] { (char)121, (char)122, (char)123 }; foreach (char charItem in charArray04) { Console.WriteLine(charItem.ToString()); } Console.WriteLine("== Convert.ToChar(x)=="); var char05 = Convert.ToChar(121); Console.WriteLine(char05); byte byte01 = 248; Console.WriteLine("Byte bb is " + byte01); Byte byte02 = Convert.ToByte(255); Console.WriteLine(); Console.WriteLine("==Bytes=="); var byteArray = new byte[] { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 255, 232 }; foreach (byte bbb in byteArray) { Console.WriteLine(bbb.ToString()); } foreach (byte bbb in byteArray) { Console.Write(Convert.ToChar(bbb)); } int[] array01 = new int[10]; // 1d int[] array02 = { 1, 2, 3 }; // literals Console.WriteLine("array length is " + array02.Length); Console.WriteLine("array count is " + array02.Count()); int[,] arraygrid = new int[5, 5]; // 2d DateTime date01 = new DateTime(); Console.WriteLine(date01); DateTime date02 = DateTime.Today; Console.WriteLine(date02); DateTime date03 = DateTime.Now; Console.WriteLine(date03); date03.AddDays(7); date03.AddDays(7.0); date03.Add(new TimeSpan(2000)); Console.WriteLine(date03); date03.AddYears(24); Console.WriteLine(date03); var Interval01 = date03 - date02; Console.WriteLine(Interval01); Console.WriteLine(); Console.WriteLine("Byte uses {0} bytes", sizeof(byte)); Console.WriteLine("with min value {0}", byte.MinValue); Console.WriteLine("and max value {0}", byte.MaxValue); Console.WriteLine("Int uses {0} bytes", sizeof(int)); Console.WriteLine("with min value {0}", int.MinValue); Console.WriteLine("and max value {0}", int.MaxValue); Console.WriteLine("Short uses {0} bytes", sizeof(short)); Console.WriteLine("with min value {0}", short.MinValue); Console.WriteLine("and max value {0}", short.MaxValue); Console.WriteLine("Int uses {0} bytes", sizeof(long)); Console.WriteLine("with min value {0}", long.MinValue); Console.WriteLine("and max value {0}", long.MaxValue); Console.WriteLine(); Console.WriteLine("==Checked vs Not Checked=="); // Not checked : i2 overflows int i1 = 2147483647; Console.WriteLine("Not checked : " + i1); int i2 = i1 * 2; Console.WriteLine("Not checked : {0}", i2); checked { int i3 = 2147483647; Console.WriteLine("Not checked : " + i3); // uncomment to create a runtime exception int i4 = i1 * 2; // Console.WriteLine("Not checked : {0}", i4); } // Console.WriteLine(checked(3245234523453245324*100)); Console.WriteLine(unchecked (3245234523453245324 * 100)); var plainText = "hello world…"; var rawBytes = Encoding.Default.GetBytes(plainText); // view details class t : Type { } // using letters to define var money01 = 1.27M; Console.WriteLine($"money01 = { money01}"); var uu = 123L; Console.WriteLine($"uu = {uu}"); var ss = (Int16)123; Console.WriteLine($"ss = {ss}"); var ff = 1.23F; Console.WriteLine($"ff = {ff}"); var y = 0f; // y is single Console.WriteLine($"y = {y}"); var z = 0d; // z is double Console.WriteLine($"z = {z}"); var r = 0m; // r is decimal Console.WriteLine($"r = {r}"); var iii = 0U; // i is unsigned int Console.WriteLine($"iii = {iii}"); var jjjj = 0L; // j is long (note capital L for clarity) Console.WriteLine($"jjj = {jjjj}"); var kkkk = 0UL; // k is unsigned long (note capital L for clarity) Console.WriteLine($"kkkk = {kkkk}"); // Default values Console.WriteLine("== default values == "); int myNum01 = new int(); Console.WriteLine(myNum01); int myNum02 = default(int); Console.WriteLine(myNum02); string myString01 = default(string); Console.WriteLine(myString01); string myString02 = null; Console.WriteLine(myString02); //int.TryParse string myNumberAsString = "1234"; int myNumber; int.TryParse(myNumberAsString, out myNumber); Console.WriteLine(myNumber); Console.WriteLine(myNumber.GetType()); Console.ReadLine(); }
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(); }
private void button2_Click(object sender, EventArgs e) { RestApi search = new RestApi(); //https://api.shodan.io/shodan/host/{ip}?key={YOUR_API_KEY} search.endpoint = RestApi.baseUrl + "host/" + ipTxt.Text + "?key=" + RestApi.apiKey + "&minify=true"; string response = search.makeRequest(); //convert the response json array into dictionery then display it Dictionary <string, object> x = JsonConvert.DeserializeObject <Dictionary <string, object> >(response); string temp1 = string.Empty; Int64 temp2 = 1; try { foreach (var item in x) { if (item.Value != null)//shouldn't display null values or non (string / integer) values { string key = (item.Key), value = (item.Value.ToString()); if (item.Value.GetType() == temp1.GetType() || item.Value.GetType() == temp2.GetType()) { debugOutput(key + " : " + value); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void TestIsPrimitiveMethod_Int64() { Int64 value = 1; TypeUtil.IsPrimitive(value.GetType()).IsTrue(); }
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(); }
static void Main(string[] args) { sbyte sb1 = 3; SByte sb2 = 3; Console.WriteLine(sb1.GetType()); Console.WriteLine(sb2.GetType()); byte b1 = 3; Byte b2 = 3; Console.WriteLine(b1.GetType()); Console.WriteLine(b2.GetType()); short s1 = 3; Int16 s2 = 3; Console.WriteLine(s1.GetType()); Console.WriteLine(s2.GetType()); ushort us1 = 3; UInt16 us2 = 3; Console.WriteLine(us1.GetType()); Console.WriteLine(us2.GetType()); int i1 = 3; Int32 i2 = 3; Console.WriteLine(i1.GetType()); Console.WriteLine(i2.GetType()); uint ui1 = 3; UInt32 ui2 = 3; Console.WriteLine(ui1.GetType()); Console.WriteLine(ui2.GetType()); long l1 = 3; Int64 l2 = 3; Console.WriteLine(l1.GetType()); Console.WriteLine(l2.GetType()); ulong ul1 = 3; UInt64 ul2 = 3; Console.WriteLine(ul1.GetType()); Console.WriteLine(ul2.GetType()); float f1 = 3.0f; Single f2 = 3.0f; Console.WriteLine(f1.GetType()); Console.WriteLine(f2.GetType()); double d1 = 3.0d; Double d2 = 3.0d; Console.WriteLine(d1.GetType()); Console.WriteLine(d2.GetType()); decimal dl1 = 3.0m; Decimal dl2 = 3.0m; Console.WriteLine(dl1.GetType()); Console.WriteLine(dl2.GetType()); char ch1 = 'A'; Char ch2 = 'B'; Console.WriteLine(ch1.GetType()); Console.WriteLine(ch2.GetType()); string st1 = "str"; String st2 = "str"; Console.WriteLine(st1.GetType()); Console.WriteLine(st2.GetType()); object o1 = 3; Object o2 = 3; Console.WriteLine(o1.GetType()); Console.WriteLine(o2.GetType()); Console.Read(); }
static void Main(string[] args) { //Ex.7 Console.WriteLine($"Работа с исключениями (задание1):\0"); Console.Write($"\0Введите число:\0"); double element = Convert.ToInt32(Console.ReadLine()); if (element == 0) { Debug.Assert(element != 0, "Произойдет деление на нуль!"); } try { if (element != 0) { double y = (8.0 / element); Console.WriteLine(y); } else { throw new Exception_1("\0Нельзя делить на нуль!"); } } catch (Exception_1 ex1) { Console.WriteLine(ex1.Message); Console.WriteLine(ex1.StackTrace); } Console.WriteLine(); Int64 el = 2; Console.WriteLine($"\0Наш элемент:{el.GetType()}\0"); try { if (el.GetTypeCode() == TypeCode.Byte) { el = 1; Console.WriteLine(el); } else { throw new FromEx2("\0Невозможно преобразовать!"); } } catch (FromEx2 u) { Console.WriteLine(u.Message); Console.WriteLine(u.StackTrace); } Console.WriteLine(); string h = null; try { if (h != null) { string h2 = h.ToUpper(); Console.WriteLine(h2); } else { throw new FromEx("\0Невозможно работать с null"); } } catch (FromEx ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } Console.WriteLine(); int[] array_ = new int[2]; for (int i = 0; i < array_.Length; i++) { array_[i] = 6; } try { array_[3] = 5; } catch (IndexOutOfRangeException ex) when(array_.Length < 3) { Console.WriteLine(ex.Message); } Console.WriteLine(); try { int al = 8; int elll = 0; int y = al / elll; Console.WriteLine(y); } catch { Console.WriteLine("\0Ошибка!"); } finally { Console.WriteLine("\0Конец программы!"); } Console.WriteLine("\0Работа с Assert"); // For abstract class Console.WriteLine("Полиморфизм (сложение длин строк):"); Inventar skameika = new Skameika() { name = "скамейка", count = 8 }; string a = "Bed"; Console.WriteLine($"\0{skameika.V_method(a.Length)}"); Console.WriteLine(); // For interface Brusia br = new Brusia() { name = "брусья", count = 3 }; string brusia2 = "Brusia"; Console.WriteLine($"Реализация работы с интерфейсом:\0"); Console.WriteLine($"\0сумма пар брусьев:\0{br.Summ(br.brusia, 4)}"); Console.WriteLine($"\0сумма строк:\0{br.Summ(brusia2)}"); Console.WriteLine(); Console.WriteLine("Введите общее количество мячей:\0"); int balls1 = Int32.Parse(Console.ReadLine()); Console.WriteLine("Введите количество мячей, которые вы можете предоставить:\0"); int balls2 = Int32.Parse(Console.ReadLine()); Ball ball = new Ball(); Console.WriteLine($"\0сумма ваших мячей:\0{ball.Summ(balls1, balls2)}"); Console.WriteLine($"\0произведение ваших мячей:\0{ball.Umn(balls1, balls2)}"); Console.WriteLine(); Console.WriteLine("Реализация работы с is:"); Maty maty = new Maty() { name = "маты", count = 10 }; Console.Write("\0принадлежит ли созданный объект maty классу Ball:\0"); maty.Proverka(maty); Console.WriteLine(); Tennis one = new Tennis(); Console.WriteLine("Переопределенные методы:\0"); Console.WriteLine($"\0Equals:\0{one.Equals("Table")};"); Console.WriteLine($"\0GetHashCode:\0{one.GetHashCode()};"); Console.WriteLine($"\0ToString:\0{one.ToString()};"); Console.WriteLine(); Console.WriteLine("Информация о классах:\0"); Console.WriteLine(skameika.ToString()); Console.WriteLine(br.ToString()); Bask_ball bas = new Bask_ball(); Console.WriteLine(bas.ToString()); Console.WriteLine(); Console.WriteLine($"Работа класса Printer:\0"); Inventar[] array = new Inventar[4]; array[0] = skameika; array[1] = maty; array[2] = ball; array[3] = br; Printer pr = new Printer(); for (int i = 0; i < 4; i++) { pr.iAmPrinting(array[i]); } Console.WriteLine(); Console.WriteLine("Работа со структурой:"); Zal zal; zal.thing = "мяч"; zal.count = 6; zal.Print(); Console.WriteLine(); Console.WriteLine("Работа с перечислением:"); AllThings things; things = AllThings.table; Console.WriteLine($"Количество столов:\0{(int)things}"); Console.WriteLine(); Console.WriteLine("Работа с контейнером:"); Container_for_Zal cont = new Container_for_Zal(); cont.Push(skameika); cont.Push(br); cont.Push(maty); Console.WriteLine("\tВесь список вещей:\0"); cont.Show(); cont.Delete(br); Console.WriteLine("\tСписок вещей после удаления одной из них:\0"); cont.Show(); Console.Write("\0Общее количество вещей:\0"); cont.Count_(); Console.WriteLine(); Console.WriteLine("Работа с контроллером:"); Controller cont1 = new Controller(cont); cont1.Sort(); }
// Contiene las 10 funciones para cada tipo de variable public String getRestaNegativos(int Nint, Int64 Nint64, float Nfloat, double Ndouble, int limite) { if (Nint == 1) { Tiempo contador = new Tiempo(); contador.iniciaContador(); // Comienza int numero = 1; int resultado = 0; int auxiliar = 0; int auxiliar2 = 0; while (numero <= limite) { resultado = auxiliar - auxiliar2; auxiliar = (numero * 5) * -1; auxiliar2 = (numero * 2) * -1; numero += 1; } contador.terminaContador(); // Finaliza Console.WriteLine(numero.GetType()); Console.WriteLine("Tiempo : " + contador.getTiempoTotal().TotalMilliseconds + " ms "); } else if (Nint64 == 1) { Tiempo contador = new Tiempo(); contador.iniciaContador(); // Comienza Int64 numero = 1; Int64 resultado = 0; Int64 auxiliar = 0; Int64 auxiliar2 = 0; while (numero <= limite) { resultado = auxiliar - auxiliar2; auxiliar = (numero * 5) * -1; auxiliar2 = (numero * 2) * -1; numero += 1; } contador.terminaContador(); // Finaliza Console.WriteLine(numero.GetType()); Console.WriteLine("Tiempo : " + contador.getTiempoTotal().TotalMilliseconds + " ms "); } else if (Nfloat == 1) { Tiempo contador = new Tiempo(); contador.iniciaContador(); // Comienza float numero = 1; float resultado = 0; float auxiliar = 0; float auxiliar2 = 0; while (numero <= limite) { resultado = auxiliar - auxiliar2; auxiliar = (numero * 5) * -1; auxiliar2 = (numero * 2) * -1; numero += 1; } contador.terminaContador(); // Finaliza Console.WriteLine(numero.GetType()); Console.WriteLine("Tiempo : " + contador.getTiempoTotal().TotalMilliseconds + " ms "); } else if (Ndouble == 1) { Tiempo contador = new Tiempo(); contador.iniciaContador(); // Comienza double numero = 1; double resultado = 0; double auxiliar = 0; double auxiliar2 = 0; while (numero <= limite) { resultado = auxiliar - auxiliar2; auxiliar = (numero * 5) * -1; auxiliar2 = (numero * 2) * -1; numero += 1; } contador.terminaContador(); // Finaliza Console.WriteLine(numero.GetType()); Console.WriteLine("Tiempo : " + contador.getTiempoTotal().TotalMilliseconds + " ms "); } return("true"); }
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"); } }
static void Main(string[] args) { sbyte a1 = -10; SByte a2 = -11; Console.WriteLine(a1.GetType()); Console.WriteLine(a2.GetType()); short b1 = -500; Int16 b2 = -400; Console.WriteLine(b1.GetType()); Console.WriteLine(b2.GetType()); int c1 = 123; Int32 c2 = -123; Console.WriteLine(c1.GetType()); Console.WriteLine(c2.GetType()); long d1 = -100000; Int64 d2 = 110000; Console.WriteLine(d1.GetType()); Console.WriteLine(d2.GetType()); byte e1 = 99; Byte e2 = 98; Console.WriteLine(e1.GetType()); Console.WriteLine(e2.GetType()); ushort f1 = 655; UInt16 f2 = 666; Console.WriteLine(f1.GetType()); Console.WriteLine(f2.GetType()); char g1 = 'c'; Char g2 = '!'; Console.WriteLine(g1.GetType()); Console.WriteLine(g2.GetType()); uint h1 = 333; UInt32 h2 = 334; Console.WriteLine(h1.GetType()); Console.WriteLine(h2.GetType()); ulong i1 = 12321; UInt64 i2 = 123321; Console.WriteLine(i1.GetType()); Console.WriteLine(i2.GetType()); float k1 = 2.2f; Single k2 = 45.05f; Console.WriteLine(k1.GetType()); Console.WriteLine(k2.GetType()); double l1 = 8.098; Double l2 = 8.98; Console.WriteLine(l1.GetType()); Console.WriteLine(l2.GetType()); decimal m1 = 1.2E3m; Decimal m2 = 1.3E2m; Console.WriteLine(m1.GetType()); Console.WriteLine(m2.GetType()); object obj1 = 9; Object obj2 = true; Console.WriteLine(obj1.GetType()); Console.WriteLine(obj2.GetType()); string str1 = "valar morghulis"; String str2 = "valar dohaeris"; Console.WriteLine(str1.GetType()); Console.WriteLine(str2.GetType()); }
static void Main(string[] args) { sbyte example1 = 1; Console.WriteLine(example1.GetType()); SByte example2 = 1; Console.WriteLine(example2.GetType()); short example3 = 1; Console.WriteLine(example3.GetType()); Int16 example4 = 1; Console.WriteLine(example4.GetType()); int example5 = 1; Console.WriteLine(example5.GetType()); Int32 example6 = 1; Console.WriteLine(example6.GetType()); long example7 = 1; Console.WriteLine(example7.GetType()); Int64 example8 = 1; Console.WriteLine(example8.GetType()); byte example9 = 1; Console.WriteLine(example9.GetType()); Byte example10 = 1; Console.WriteLine(example10.GetType()); ushort example11 = 1; Console.WriteLine(example11.GetType()); UInt16 example12 = 1; Console.WriteLine(example12.GetType()); char example13 = '1'; Console.WriteLine(example13.GetType()); Char example14 = '1'; Console.WriteLine(example14.GetType()); uint example15 = 1; Console.WriteLine(example15.GetType()); UInt32 example16 = 1; Console.WriteLine(example16.GetType()); ulong example17 = 1; Console.WriteLine(example17.GetType()); UInt64 example18 = 1; Console.WriteLine(example18.GetType()); float example19 = 1; Console.WriteLine(example19.GetType()); Single example20 = 1; Console.WriteLine(example20.GetType()); double example21 = 1; Console.WriteLine(example21.GetType()); Double example22 = 1; Console.WriteLine(example22.GetType()); decimal example23 = 1; Console.WriteLine(example23.GetType()); Decimal example24 = 1; Console.WriteLine(example24.GetType()); }
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 bool PosTest <T>(int id, T curValue, Int64 expValue) { bool retVal = true; Int64 newValue; IFormatProvider myfp; TestLibrary.TestFramework.BeginScenario("PosTest" + id + ": Convert.ToInt64(...) (curValue:" + typeof(T) + " " + curValue + " newType:" + expValue.GetType() + ")"); try { newValue = Convert.ToInt64(curValue); if (!newValue.Equals(expValue)) { TestLibrary.TestFramework.LogError("000", "Value mismatch: Expected(" + expValue + ") Actual(" + newValue + ")"); retVal = false; } myfp = null; newValue = Convert.ToInt64(curValue, myfp); 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) { sbyte a1 = 11; SByte a2 = 11; Console.WriteLine(a1.GetType()); Console.WriteLine(a2.GetType()); short b1 = 11; Int16 b2 = 11; Console.WriteLine(b1.GetType()); Console.WriteLine(b2.GetType()); int c1 = 11; Int32 c2 = 11; Console.WriteLine(c1.GetType()); Console.WriteLine(c2.GetType()); long d1 = 11; Int64 d2 = 11; Console.WriteLine(d1.GetType()); Console.WriteLine(d2.GetType()); byte e1 = 11; Byte e2 = 11; Console.WriteLine(e1.GetType()); Console.WriteLine(e2.GetType()); ushort f1 = 11; UInt32 f2 = 11; Console.WriteLine(f1.GetType()); Console.WriteLine(f2.GetType()); char g1 = 'a'; Char g2 = 'a'; Console.WriteLine(g1.GetType()); Console.WriteLine(g2.GetType()); uint h1 = 11; UInt32 h2 = 11; Console.WriteLine(h1.GetType()); Console.WriteLine(h2.GetType()); ulong i1 = 11; UInt64 i2 = 11; Console.WriteLine(i1.GetType()); Console.WriteLine(i2.GetType()); float j1 = 11; Single j2 = 11; Console.WriteLine(j1.GetType()); Console.WriteLine(j2.GetType()); double k1 = 11; Double k2 = 11; Console.WriteLine(k1.GetType()); Console.WriteLine(k2.GetType()); decimal l1 = 11; Decimal l2 = 11; Console.WriteLine(l1.GetType()); Console.WriteLine(l2.GetType()); string m1 = "11"; String m2 = "11"; Console.WriteLine(m1.GetType()); Console.WriteLine(m2.GetType()); object n1 = 123456789; Object n2 = 1234.56789; Console.WriteLine(n1.GetType()); Console.WriteLine(n2.GetType()); Console.ReadKey(); }