Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
Monday, October 22, 2012
Thursday, May 19, 2011
C# Intrinsic data types
The intrinsic types
C# type Size (in bytes) .NET type Description
byte 1 Byte Unsigned (values 0-255).
char 2 Char Unicode characters.
bool 1 Boolean True or false.
sbyte 1 SByte Signed (values -128 to 127).
short 2 Int16 Signed (short) (values -32,768 to 32,767).
ushort 2 UInt16 Unsigned (short) (values 0 to 65,535).
int 4 Int32 Signed integer values between -2,147,483,648 and 2,147,483,647.
uint 4 UInt32 Unsigned integer values between 0 and 4,294,967,295.
float 4 Single Floating point number. Holds the values from approximately +/-1.5 * 10-45 to approximately +/-3.4 * 1038 with 7 significant figures.
double 8 Double Double-precision floating point; holds the values from approximately +/-5.0 * 10-324 to approximately +/-1.8 * 10308 with 15–16 significant figures.
decimal 12 Decimal Fixed-precision up to 28 digits and the position of the decimal point. This is typically used in financial calculations. Requires the suffix "m" or "M."
long 8 Int64 Signed integers ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
ulong 8 UInt64 Unsigned integers ranging from 0 to approximately 1.85 * 1019.
C# type Size (in bytes) .NET type Description
byte 1 Byte Unsigned (values 0-255).
char 2 Char Unicode characters.
bool 1 Boolean True or false.
sbyte 1 SByte Signed (values -128 to 127).
short 2 Int16 Signed (short) (values -32,768 to 32,767).
ushort 2 UInt16 Unsigned (short) (values 0 to 65,535).
int 4 Int32 Signed integer values between -2,147,483,648 and 2,147,483,647.
uint 4 UInt32 Unsigned integer values between 0 and 4,294,967,295.
float 4 Single Floating point number. Holds the values from approximately +/-1.5 * 10-45 to approximately +/-3.4 * 1038 with 7 significant figures.
double 8 Double Double-precision floating point; holds the values from approximately +/-5.0 * 10-324 to approximately +/-1.8 * 10308 with 15–16 significant figures.
decimal 12 Decimal Fixed-precision up to 28 digits and the position of the decimal point. This is typically used in financial calculations. Requires the suffix "m" or "M."
long 8 Int64 Signed integers ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
ulong 8 UInt64 Unsigned integers ranging from 0 to approximately 1.85 * 1019.
Tuesday, June 8, 2010
Exception.ToString() vs. Exception.Message
ToString is superior than Message. Very useful for debugging purposes!
using System;
using System.Collections.Generic;
using System.Text;
namespace ExceptionToString
{
public class MyClass {}
public class ArgExceptionExample
{
static void Main(string[] args)
{
MyClass my = new MyClass();
string s = "sometext";
try
{
int i = s.CompareTo(my);
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}\n", ex.ToString());
Console.WriteLine("Error: {0}", ex.Message);
Console.Read();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ExceptionToString
{
public class MyClass {}
public class ArgExceptionExample
{
static void Main(string[] args)
{
MyClass my = new MyClass();
string s = "sometext";
try
{
int i = s.CompareTo(my);
}
catch (Exception ex)
{
Console.WriteLine("Error: {0}\n", ex.ToString());
Console.WriteLine("Error: {0}", ex.Message);
Console.Read();
}
}
}
}
Wednesday, May 5, 2010
Validate contract in C# using REGEX
String strToTest;
String rePattern = "^[FGHJKMNQUVXZ][0-9]$";
Console.Write("Enter a String to Test for Contract:");
strToTest = Console.ReadLine();
Regex regexPattern = new Regex(rePattern);
Console.WriteLine(regexPattern.IsMatch(strToTest) == true ? "OK" : "KO");
strToTest = Console.ReadLine();
String rePattern = "^[FGHJKMNQUVXZ][0-9]$";
Console.Write("Enter a String to Test for Contract:");
strToTest = Console.ReadLine();
Regex regexPattern = new Regex(rePattern);
Console.WriteLine(regexPattern.IsMatch(strToTest) == true ? "OK" : "KO");
strToTest = Console.ReadLine();
Subscribe to:
Posts (Atom)