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> UInt32 myVariable1 = 20; UInt32 myVariable2 = 20; // 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); } }
UInt32 compareUInt32(UInt32 b, UInt32 b2) { if (b == b2) { return(b); } throw new IllegalStateException("Not got expected value for type: " + b2.GetType().ToString()); }
public void TestUint64() { Property myProperty = new Property(new Uri("ex:myProperty")); Resource r = new Resource(new Uri("ex:myResource")); UInt32 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); }
public void TestUInt32() { FileStream stream = new FileStream("Prova.bin", System.IO.FileMode.Create); CompactFormatter CFormatter = new CompactFormatter(); long start = DateTime.Now.Ticks; UInt32[] s = new UInt32[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(); UInt32[] temp = new UInt32[max]; //for(int i = 0; i<max; i++) //{ temp = (UInt32[])CFormatter2.Deserialize(stream); //} stream.Close(); long stop = DateTime.Now.Ticks; long ts = stop - start; Console.WriteLine("Elapsed Time:{0},{1},{2}", ts, start, stop); UInt32 s2 = 0; for (int i = 0; i < max; i++) { //Console.WriteLine("Deserialized {0}",temp[i]); Assert.AreEqual(temp[i], s2); s2++; } }
public void TestUInt32() { FileStream stream = new FileStream("Prova.bin", System.IO.FileMode.Create); CompactFormatter CFormatter = new CompactFormatter(); long start = DateTime.Now.Ticks; UInt32 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(); UInt32[] temp = new UInt32[max]; for (int i = 0; i < max; i++) { temp[i] = (UInt32)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++; } }
public virtual Dictionary <AuditEventPolicies, AuditEventStatus> GetAuditEventPolicies(TargetInfo targetInfo) { Dictionary <AuditEventPolicies, AuditEventStatus> retList = new Dictionary <AuditEventPolicies, AuditEventStatus>(); LSA_UNICODE_STRING systemName = string2LSAUS(targetInfo.GetAddress()); LSA_OBJECT_ATTRIBUTES objAttrs = new LSA_OBJECT_ATTRIBUTES(); IntPtr policyHandle = IntPtr.Zero; IntPtr pAuditEventsInfo = IntPtr.Zero; IntPtr pAuditCategoryGuid = IntPtr.Zero; IntPtr pAuditSubCategoryGuids = IntPtr.Zero; IntPtr pAuditPolicies = IntPtr.Zero; UInt32 lretVal = LsaOpenPolicy(ref systemName, ref objAttrs, POLICY_VIEW_AUDIT_INFORMATION, out policyHandle); uint retVal = LsaNtStatusToWinError(lretVal); if (retVal != 0) { throw new System.ComponentModel.Win32Exception((int)retVal); } try { lretVal = LsaQueryInformationPolicy(policyHandle, POLICY_INFORMATION_CLASS.PolicyAuditEventsInformation, out pAuditEventsInfo); retVal = LsaNtStatusToWinError(lretVal); if (retVal != 0) { throw new System.ComponentModel.Win32Exception((int)retVal); } // EventAuditingOptions: The index of each array element corresponds to an audit event type value in the POLICY_AUDIT_EVENT_TYPE enumeration type. // Each POLICY_AUDIT_EVENT_OPTIONS variable in the array can specify the following auditing options. // POLICY_AUDIT_EVENT_UNCHANGED, POLICY_AUDIT_EVENT_SUCCESS, POLICY_AUDIT_EVENT_FAILURE, POLICY_AUDIT_EVENT_NONE POLICY_AUDIT_EVENTS_INFO myAuditEventsInfo = new POLICY_AUDIT_EVENTS_INFO(); myAuditEventsInfo = (POLICY_AUDIT_EVENTS_INFO)Marshal.PtrToStructure(pAuditEventsInfo, myAuditEventsInfo.GetType()); for (UInt32 policyAuditEventType = 0; policyAuditEventType < myAuditEventsInfo.MaximumAuditEventCount; policyAuditEventType++) { pAuditCategoryGuid = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GUID))); if (!AuditLookupCategoryGuidFromCategoryId((POLICY_AUDIT_EVENT_TYPE)policyAuditEventType, pAuditCategoryGuid)) { int causingError = GetLastError(); throw new System.ComponentModel.Win32Exception(causingError); } String categoryName = String.Empty; AuditLookupCategoryName(pAuditCategoryGuid, ref categoryName); UInt32 status = 0; IntPtr itemPtr = new IntPtr(myAuditEventsInfo.EventAuditingOptions.ToInt64() + (Int64)policyAuditEventType * (Int64)Marshal.SizeOf(typeof(UInt32))); status = (UInt32)Marshal.PtrToStructure(itemPtr, status.GetType()); retList.Add((AuditEventPolicies)policyAuditEventType, (AuditEventStatus)(status & 0x3)); Marshal.FreeHGlobal(pAuditCategoryGuid); pAuditCategoryGuid = IntPtr.Zero; } } finally { if (pAuditEventsInfo != IntPtr.Zero) { LsaFreeMemory(pAuditEventsInfo); } if (pAuditCategoryGuid != IntPtr.Zero) { Marshal.FreeHGlobal(pAuditCategoryGuid); } LsaClose(policyHandle); } return(retList); }
public void Save(String PropertyName, UInt32 Value) { _GameSaver.CreateChildElement(_Element, PropertyName, Value.GetType(), Value.ToString(_GameSaver.CultureInfo)); }
public static string DebugString(this UInt32 v) { return(v.ToString().PadLeft(columnWidth) + " " + v.ToString("X8").PadRight(columnWidth) + v.GetType().Name); }
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) { 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 bool PosTest <T>(int id, T curValue, UInt32 expValue) { bool retVal = true; UInt32 newValue; IFormatProvider myfp; TestLibrary.TestFramework.BeginScenario("PosTest" + id + ": Convert.ToUInt32(...) (curValue:" + typeof(T) + " " + curValue + " newType:" + expValue.GetType() + ")"); try { newValue = Convert.ToUInt32(curValue); if (!newValue.Equals(expValue)) { TestLibrary.TestFramework.LogError("000", "Value mismatch: Expected(" + expValue + ") Actual(" + newValue + ")"); retVal = false; } myfp = null; newValue = Convert.ToUInt32(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); }
public void TestIsPrimitiveMethod_UInt32() { UInt32 value = 1; TypeUtil.IsPrimitive(value.GetType()).IsTrue(); }
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()); }
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(); }
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"); } }
private static void Main(string[] args) { // Deal with any args passed in if (args.Length == 0) { Console.WriteLine("You started this program with no parameters."); } else { for (var x = 0; x == args.Length; x++) { Console.WriteLine("Argument " + x + " is " + args[x]); } } // Set console size Console.SetWindowSize(Console.LargestWindowWidth / 2, Console.LargestWindowHeight / 2); Console.SetWindowPosition(0, 0); // Input various type of data // Text Console.Write("Please enter some text: "); string text = ""; try { text = Console.ReadLine(); } catch (Exception ex) { ErrorHandler(ex.Message); } // By rights you should use a null check here but the error handling would catch a null anyway // Also you do not need the .ToString() method to convert the GetType() result to a string but it is there for educational purposes Console.WriteLine("You entered: " + text + ", using a " + text.GetType().ToString() + " variable type."); Console.WriteLine(); // 32 bit Integer Console.Write("Please enter a whole number in digit(s) below which holds negative (between 2,147,483,647 and -2,147,483,648: "); int number = 0; try { number = Convert.ToInt32(Console.ReadLine()); } catch (Exception ex) { ErrorHandler(ex.Message); } Console.WriteLine("You entered: " + number + ", using a " + number.GetType() + " variable type."); Console.WriteLine(); // Boolean Console.WriteLine("Please enter true or false (boolean): "); bool yesNo = false; try { yesNo = Convert.ToBoolean(Console.ReadLine()); } catch (Exception ex) { ErrorHandler(ex.Message); } Console.WriteLine("You entered: " + yesNo + ", using a " + yesNo.GetType() + " variable type."); Console.WriteLine(); // Byte Console.WriteLine("Please enter a positive whole number in digit(s) (between 0 and 255: "); byte byteSize = 0; try { byteSize = Convert.ToByte(Console.ReadLine()); } catch (Exception ex) { ErrorHandler(ex.Message); } Console.WriteLine("You entered: " + byteSize + ", using a " + byteSize.GetType() + " variable type."); Console.WriteLine(); // 32 bit unsigned integer Console.WriteLine("Please enter a positive number in digit(s) (between 0 and 4,294,967,295: "); UInt32 unsignedInt = 0; try { unsignedInt = Convert.ToUInt32(Console.ReadLine()); } catch (Exception ex) { ErrorHandler(ex.Message); } Console.WriteLine("You entered: " + unsignedInt + ", using a " + unsignedInt.GetType() + " variable type."); Console.WriteLine(); // Char Console.WriteLine("Please press a key: "); char character = 'a'; try { character = Convert.ToChar(Console.ReadKey().KeyChar); Console.WriteLine(); } catch (Exception ex) { ErrorHandler(ex.Message); } Console.WriteLine("You entered: " + character + ", using a " + character.GetType() + " variable type."); Console.WriteLine(); // DateTime Console.WriteLine("Please enter a date (in the format YYYY MM DD so - 2001 01 01 for example): "); DateTime thisThen = new DateTime(2001, 01, 01); try { thisThen = Convert.ToDateTime(Console.ReadLine()); } catch (Exception ex) { ErrorHandler(ex.Message); } Console.WriteLine("You entered: " + thisThen.ToShortDateString() + ", using a " + thisThen.GetType() + " variable type, shortened to remove the time component."); Console.WriteLine(); // TimeSpan Console.WriteLine("Please enter a time (in the format HH MM SS so - 12 30 00 for example) with each section (hour, minute, second) on a new line: "); TimeSpan thisNow = new TimeSpan(00, 00, 00); try { // Use var for private scope variables rather than explicit types (e.g. int, string, etc.) var hour = Convert.ToInt32(Console.ReadLine()); var minute = Convert.ToInt32(Console.ReadLine()); var second = Convert.ToInt32(Console.ReadLine()); thisNow = new TimeSpan(hour, minute, second); if (thisNow.Ticks > TimeSpan.TicksPerDay) { Console.WriteLine("You entered an hour greater than 24, this would lead to a result in days."); Console.WriteLine("Whoops."); Console.ReadKey(); Environment.Exit(1); } } catch (Exception ex) { ErrorHandler(ex.Message); } Console.WriteLine("You entered: " + thisNow + ", using a " + thisNow.GetType() + " variable type."); Console.WriteLine(); // Decimal Console.WriteLine("Please enter pi to 10 decimal places (type help if you don't know): "); const decimal pi = 3.1415926536M; // Use of var here would be counter productive as compiler would // set pi as a double not a decimal also the value is never altered so it makes sense to make it a constant // the CultureInfo.InvariantCulture uses the settings defined in Windows' settings, so language, alphabet, calendar format, etc. try { var input = Console.ReadLine(); if (input == "help") { Console.WriteLine("Pi to 10 decimal places is " + pi.ToString(CultureInfo.InvariantCulture) + ". I have entered it for you."); } else { if (Convert.ToDecimal(input) == pi) { Console.WriteLine("Nicely done!"); } else if (input == "help") { Console.WriteLine("The answer is 3.1415926536."); } else { Console.WriteLine("Whoops, I am sure you were close, it is actually " + pi.ToString(CultureInfo.InvariantCulture)); } } } catch (Exception ex) { ErrorHandler(ex.Message); } Console.WriteLine("You entered: " + pi.ToString(CultureInfo.InvariantCulture) + ", using a " + pi.GetType() + " variable type."); Console.WriteLine(); // Full list Console.WriteLine("OK, so now you have a flavour of the data types C# can work with."); Console.WriteLine("For completeness sake, here is a list:"); Console.WriteLine("Boolean, Byte, Char, DateTime, Decimal, Double, Float, Integer, Long, Object, SByte, Short, String, UInteger, ULong, UShort"); Console.WriteLine("Not to mention user defined types. Yep, you can make your own should you need it!"); Console.WriteLine("Then there are other data constructs like TimeSpan, Array, List, Constant, Enum, Class, Struct, Nullables, Interface, RegEx..."); Console.WriteLine("That's a lot, no?"); Console.WriteLine(); // Exit code Console.WriteLine("Please press enter to exit."); Console.ReadLine(); }
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 static Dictionary <AuditEventPolicy, AuditEventStatus> GetPolicies() { Dictionary <AuditEventPolicy, AuditEventStatus> result = new Dictionary <AuditEventPolicy, AuditEventStatus>(); LSA_OBJECT_ATTRIBUTES objAttrs = new LSA_OBJECT_ATTRIBUTES(); IntPtr hPolicy = IntPtr.Zero; IntPtr pInfo = IntPtr.Zero; IntPtr pGuid = IntPtr.Zero; UInt32 lrc = LsaOpenPolicy(null, ref objAttrs, POLICY_VIEW_AUDIT_INFORMATION, out hPolicy); uint code = LsaNtStatusToWinError(lrc); if (code != 0) { throw new System.ComponentModel.Win32Exception((int)code); } try { // // Query the policy // lrc = LsaQueryInformationPolicy(hPolicy, POLICY_INFORMATION_CLASS.PolicyAuditEventsInformation, out pInfo); code = LsaNtStatusToWinError(lrc); if (code != 0) { throw new System.ComponentModel.Win32Exception((int)code); } POLICY_AUDIT_EVENTS_INFO info = new POLICY_AUDIT_EVENTS_INFO(); info = (POLICY_AUDIT_EVENTS_INFO)Marshal.PtrToStructure(pInfo, info.GetType()); // // Iterate through the event types // for (UInt32 eventType = 0; eventType < info.MaximumAuditEventCount; eventType++) { pGuid = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GUID))); if (AuditLookupCategoryGuidFromCategoryId((POLICY_AUDIT_EVENT_TYPE)eventType, pGuid)) { IntPtr itemPtr = new IntPtr(info.EventAuditingOptions.ToInt64() + (Int64)eventType * (Int64)Marshal.SizeOf(typeof(UInt32))); UInt32 status = 0; status = (UInt32)Marshal.PtrToStructure(itemPtr, status.GetType()); result.Add((AuditEventPolicy)eventType, (AuditEventStatus)(status & 0x3)); Marshal.FreeHGlobal(pGuid); pGuid = IntPtr.Zero; } else { throw new System.ComponentModel.Win32Exception(GetLastError()); } } } finally { // // Cleanup // if (pInfo != IntPtr.Zero) { LsaFreeMemory(pInfo); } if (pGuid != IntPtr.Zero) { Marshal.FreeHGlobal(pGuid); } LsaClose(hPolicy); } return(result); }
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) { 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(); }
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()); }