Wednesday, July 30, 2014

#201 – You Can Leak Memory in C# | 2,000 Things You Should Know About C#

Nope, this code example is not a memory leak.

re:
 public static List<Person> userLog;
 
static void RecordUserInfo(Person justLoggedIn)
{
    userLog.Add(justLoggedIn);
}

#182 – C# is (Mostly) Strongly Typed | 2,000 Things You Should Know About C#

#182 – C# is (Mostly) Strongly Typed | 2,000 Things You Should Know About C#:



'via Blog this'



Hehe.

#75 – New Bits When Shifting | 2,000 Things You Should Know About C#

For future reference:

#75 – New Bits When Shifting

When doing bitwise shifting using the << and >> operators, the data value being shifted will always shift new bits in–from the left when right shifting, or from the right when left shifting.  The value of the new bits depend on the direction of the shift and the data type being shifted.
  • Right shift
    • If shifting int or long, new bits at left match sign of the value
    • If shifting uint or ulong, new bits at left are 0-valued
  • Left shift
    • New bits at right are 0-valued
Shift operations can never result in an overflow.

#12 – Read Command Line Arguments | 2,000 Things You Should Know About C#

#12 – Read Command Line Arguments | 2,000 Things You Should Know About C#:



'via Blog this'



Adding a ToList() makes them even easier to use.

#9 – Main() Should Not Be Public | 2,000 Things You Should Know About C#

#9 – Main() Should Not Be Public | 2,000 Things You Should Know About C#:



'via Blog this'



Really? Hmm.. did not know this. And now I do. :)

Monday, July 14, 2014

Software Product Development & SEO: .Net Double vs. Decimal

From their page:

.Net Double vs. Decimal

One twist with floating-point values is that they cannot represent every possible number. In part this is because the types are of limited size, e.g. Double only has 64-bits of data to work with. The number base used to represent values also has an effect. The .Net float and Double are encoded in base 2 (binary) format. It's not possible to represent every base 10 decimal number in base 2.

To increase accuracy, use the Decimal data type. The .Net Double data type is a 64-bit floating point value whereas the .Net Decimal data type is a 128-bit floating point value. These extra bits alone might be sufficent to make the Decimal type more accurately represent numbers than Double. However, unlike Double, Decimal is encoded in base 10. This means it can exactly represent base 10 numbers, i.e. the number system humans use, and make it an ideal type for financial calculations. The way the type works allows 28 digits of accuracy, i.e. you can represent 28 decimal digits with the decimal point moved to any position amongst the digits.

So why use Double if Decimal is available? The downside with Decimal is performance. Decimal operations can take 20 to 40 times longer than Double calculations. Most, if not all, processors used in PCs these days have 64-bit floating-point support built into the processor. Decimal operations however have to be done in software and take much longer to execute.