User Tools

Site Tools


programming:simple_data_types

Simple Data Types in C#

int

int, or integer, is a data type that represents whole numerical values. This means that if you are assigning an integer value, it cannot contain decimals.
Example of acceptable assignment of value:

int num1 = 1; 
int num2 = 42;

Example of unacceptable assignment of value:

int num1 = 1.5; //produces an error

Upon initialization, if a value is not assigned to an integer, it starts with a value of 0. Example of an int declaration that isn't assigned a value:

int num;

When assigning a value to an int, the value assignment can be a number, operation to obtain a number, a method that returns an integer or an integer property.
Examples of acceptable assignments include:

int num1 = 5 - 2; //stores 3 in num1
int num2 = num1 * 2; //takes num1 and multiplies it by 2, storing 6 in num2
int num3 = MethodReturningInt();
int num4 = Class.Property;

number++ unary operators: add or subtract 1 before or after operation

  1. number–
  2. ++number
  3. –number

double

  1. double dub
  2. double dub2 = 5.5
  3. dub = 1.0

bool

  1. bool eval = true
  2. bool eval2 = false
  3. bool eval3 = 1;true - bool eval4 = 0;false

char

char c1 = ' ' char c2 = '%' char c3 = 'a'

string

  1. string s1 = “this is a string”
  2. string s2
  3. s2 = s1.substring(0,4)
  4. string s3 = c1 + c2 + c3

common problems

  1. double uhoh = (2.5 * 4.2) + 1
  2. ' vs “ with strings/chars
  3. bool non 1 is false, or non 0 is true idk

Back to the C# page

programming/simple_data_types.txt · Last modified: 2018/11/06 23:52 by coatsd