Professional Documents
Culture Documents
The following page contains quick references and general informations about the C# and .NET framework.
o o o o o o
List of Reserved Keywords Operator Precedence Chart Casing Styles in .NET Decimal to Binary Conversion Binary to Decimal Conversion Converting Negative Numbers to Binary
abstract byte class delegate event fixed if internal new override readonly short struct try unsafe volatile
locations.
as case const do explicit float implicit is null params ref sizeof switch typeof ushort while
base catch continue double extern for in lock object private return stackalloc this uint using
bool char decimal else false foreach int long operator protected sbyte static throw ulong virtual
break checked default enum finally goto interface namespace out public sealed string true unchecked void
The following are contextual keywords that are only treated as keywords at special events and
add equals
alias from
ascending get
by global
descending group
on set
orderby value
Operator . () [] ++ new typeof sizeof checked unchecked + ! ~ ++ (type) * / % + << >> < > <= >= is as
Type member access method call element access postfix increment postfix decrement object creation get the type of object get the size in bytes of a type checked evaluation unchecked evaluation unary plus unary minus logical negation bitwise not operator prefix increment prefix decrement casting multiplication division modulus/remainder addition subtraction left shift operator right shift operator less than greater than less than or equal to greater than or equal to type comparison type conversion
Associativity
left-to-right
right-to-left
left-to-right
left-to-right
left-to-right
Type is not equal to is equal to bitwise AND bitwise XOR bitwise OR logical AND logical OR null coalescing conditional assignment multiplication assignment division assignment modulus assignment addition assignment subtraction assignment left shift assignment right shift assignment bitwise AND assignment bitwise XOR assignment bitwise OR assignment
right-to-left
Methods. All the methods in the .NET Framework are named using the Pascal Casing. If you are creating methods, use Pascal Casing as well. Although there is one exception. When naming event handlers for controls on a form in C#, the method usually starts with the name of the control (which starts with lower case) followed by an underscore and then the name of the event.
Property. When naming a property, we usually follow the name of the private data member it references. For example, if you have a member called myName, we name the corresponding property with MyName.
o o
Class. Classes are also named using Pascal Casing. It is apparent on all the classes of the .NET Framework. Interface. When naming an interface, always precede it with a capital I followed by the name of the interface starting also with a capital letter. For example, If I want to make an interface named Clickable, I will name it IClickable.
Namespaces. When you write your namespace, you should use Pascal Casing as well.
o o o o
Now, we need to remember a simple sequence. Binaries are base 2, so we use 2 as a base and raise it to a power starting with 0.
Notice that we start with 1 and the next one is double its value which is 2. The following ones are just doubled values of their preceding values. With this values we can now get the binary equivalent of our decimal number. To start, find the highest number that does not exceed our current value whic is 54. In this case, 32. We place a 1 in the position where the 32 is located.
We now subtract 32 from 54 (54 32 = 22). Our current value is now 22. Repeat the step of finding the highest value that does not exceed our current value which is 22. The number 16 qualifies our condition so again, place a 1 where 16 is located.
We then subtract 16 from 22 (22 16 = 6) making 6 our new current value. Find the largest number in the sequence that does not exceed six. 8 exceeds 6, so we should use 4 and place again a 1 in its position.
We subtract 4 from 6 (6 4 = 2) and we find the value that does not exceed our new current value 2. Theres only one number in the sequence that does not exceed 2, and thats 2 itself. So place again 1 in its position. Subtracting 2 from our current value 2 results to 0. This time, we can now stop adding 1s.
We finally arrived to the binary equivalent of 54 which is 00110110. We can omit the leading 0s and write 110110 as the binary equivalent of 54. Please note that higher numbers require more bits (slots) for conversions. How can we know if a number fits 8 bits. Simply double the last number which is 128 and we get 256. All the number below 256 can be converted using 8 bits. If a decimal to convert is 256 or higher, then we need to add more bits when converting. For example, if we want to convert 312, then we will be needing 9 bits.
The value of the 9th bit is 28 or 256 which is simply a doubled value of its previous bit which is 128. 9 bits can only contain values below 512 which is twice the value of 256. Again, if you have a value equal or greater than 512, then you need to add again 1 more bits.
Converting from binary to decimal is easy. You first need to know the positional values of each bit. Suppose we have a binary number 10100111 that we need to convert to decimal.
Positional values starts from 20 which is 1 to 2n-1 where n is the number of bits or digits. Since we have 8 bits, the last positional value is 28-1 = 27 = 128. We write the positional values from right to left. Once we have determined the positional values, we simply add all the positional values that has 1 as its bit.
We now arrived at 167 as the final decimal answer for our binary number 10100111.
if the leftmost bit is 1, then the number is considered negative, if it is 0, the number is considered positive. Therefore, when using int as the type, the 32nd bit is not included when calculating a values decimal value. After all 4,294,967,289 will not fit in an int variable. You should use long or uint instead. To prove that the final binary result is really -7. We can add it to the binary value of 7. The result should be 0 (-7 + 7 = 0). 11111111111111111111111111111001 + 00000000000000000000000000000111 ---------------------------------00000000000000000000000000000000 If you dont know how to add binaries, the following is the three possible combinations and their results. 1 + 0 = 1 0 + 1 = 1 1 + 1 = 0 carry 1 Since the first pair of digit is both 1, the first digit of the answer is 0 and 1 is carry over to the next column and so on until we reach the final column. In the final column there should still be one being carried over from the last column so the result is still 0 and we discard the 1 to be carried.