Additional Math Functions in C#

Topic Overview Division in C# follows standard “integer division” rules when done with integer types. Many things are implicitly cast from narrow types to wider types. You can explicitly cast from one type to another by putting the type you want in parentheses in front (float a = (float)3.4948393;) Division by zero causes an exception to be thrown for integer types, and results in infinity for floating point types. NaN, PositiveInfinity, and NegativeInfinity are defined for the float and double types (float.NaN or Double.PositiveInfinity for example)….

Read More

LINQ
 to 
SQL 
in 
C# – Cheat Sheet

LINQ
 to 
SQL
 in
 C# – Cheat
 Sheet Database context & database create var db = new MyDataContext(@”server=.\SQLEXPRESS;database=my;integrated security=SSPI”); if (!db.DatabaseExists()) db.CreateDatabase(); Select one Insert var only = db.Customers.SingleOrDefault(c => c.CustID == “CHIPS”); var first = db.Customers.FirstOrDefault(c => c.CustID == “CHIPS”); var customer = new Customer() { CustID = “CHIPS”, CompanyName = “Mr. Chips” }; db.Customers.InsertOnSubmit(customer); db.SubmitChanges();   – –  – – – – – – – – – – – – – – – – – – –…

Read More

Basic Math in C#

In a Nutshell Arithmetic in C# is very similar to virtually every other programming language out there, particularly C++, C, and Java. Addition works like this: int a = 3 + 4; Subtraction works like this: // int b = 7 – 2; Multiplication uses the asterisk character (‘*’) like this: //int c = 4 * 3; Division uses the forward slash character (‘/’) like this: int d = 21 / 7; The modulus operator (‘%’) gets the remainder of a…

Read More

Posted in Programming Comments Off on Basic Math in C#
Built-in C# Data Types

C# is a strongly-typed language. Before a value can be stored in a variable, the type of the variable must be specified, as in the following examples: int a = 1; string s = “Hello”; XmlDocument tempDocument = new XmlDocument();   Note that the type must be specified both for simple, built-in types such as an int, and for complex or custom types such as XmlDocument.   C# includes support for the following built-in data types: Data Type Range byte 0…

Read More

Bitwise Operations in C#

C# has lots of flexibility over manipulating with bits. Before I start explaining about bit wise manipulation I would like to give some inputs on binary operations. Binary numbers With only two symbols you can represent any type of information you want, these symbols can be {a,b}, {0,1} or the {beep, beeeep} of the Morse code. When you want to work with boolean (1) expressions or place multiple values in a single byte (group of 8 bit), it is…

Read More

Posted in Programming Comments Off on Bitwise Operations in C#