Difference between revisions of "Constants - Variables - Data Types"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Video)
 
(20 intermediate revisions by 5 users not shown)
Line 1: Line 1:
There are 9 types of data types. These include Boolean, string, integer, double, decimal, character,  byte, float and long.
+
=Video=
 +
<youtube>https://www.youtube.com/watch?v=aJyx-CnfutI&list=PLCiOXwirraUCUY64UIv4NNx4losEKMJwd&t=4s&index=1</youtube>
  
*Boolean is a binary value is true or false.  
+
https://www.youtube.com/watch?v=aJyx-CnfutI&list=PLCiOXwirraUCUY64UIv4NNx4losEKMJwd&t=4s&index=1
*String is used for storing characters in word form.  
+
 
Integer is used to store whole numbers.
+
<youtube>https://www.youtube.com/watch?v=heLqoaQVZEo&list=PLCiOXwirraUCUY64UIv4NNx4losEKMJwd&index=3</youtube>
Double is used to store numbers where there are numbers before and after the decimal point.
+
 
decimal is used for numbers only after the decimal point.
+
https://www.youtube.com/watch?v=heLqoaQVZEo&list=PLCiOXwirraUCUY64UIv4NNx4losEKMJwd&index=3
Character is used to store single letters.
+
 
Byte is used to store a byte( eight 1's or 0's).
+
=Intro=
 +
There are 9 types of data types. These include boolean, string, integer, double, decimal, character,  byte, float and long:
 +
 
 +
 
 +
'''Boolean''' is a binary value, being either true or false.
 +
 
 +
<syntaxhighlight lang="csharp">bool example = true;</syntaxhighlight>
 +
 
 +
 
 +
'''String''' is used for storing characters in word form.
 +
 
 +
<syntaxhighlight lang="csharp">string example = "hello world";</syntaxhighlight>
 +
 
 +
 
 +
'''Integer''' is used to store whole numbers (32 bit values).
 +
 
 +
<syntaxhighlight lang="csharp">int example = 457568368;</syntaxhighlight>
 +
 
 +
 
 +
'''Double''' is used to store numbers where there are numbers before and after the decimal point, using 64 bits of memory.
 +
 
 +
<syntaxhighlight lang="csharp">double example = 3.3;</syntaxhighlight>
 +
 
 +
 
 +
'''Decimal''' is used to store larger numbers with information before and after the decimal point, using 128 bits of memory.
 +
 
 +
<syntaxhighlight lang="csharp">decimal example = 12.593;</syntaxhighlight>
 +
 
 +
 
 +
'''Character''' is used to store single letters.
 +
 
 +
<syntaxhighlight lang="csharp">char example = 'A';</syntaxhighlight>
 +
 
 +
 
 +
'''Byte''' is used to store a byte (eight bits). In C#, it is specifically an 8 bit integer (0-255).
 +
 
 +
<syntaxhighlight lang="csharp">byte example = 255;</syntaxhighlight>
 +
 
 +
 
 +
'''Float''' is used to store a 32 bit decimal number, which must be defined as being a float using "F" or "f" to distinguish it from a double, or it may cause compilation errors.
 +
 
 +
<syntaxhighlight lang="csharp">float example = 9.4F;</syntaxhighlight>
 +
 
 +
 
 +
'''Long integer''' is also used to store whole numbers (However these are 64 bit values).
 +
 
 +
<syntaxhighlight lang="csharp">long example = 7846354759340276482;</syntaxhighlight>
 +
 
 +
 
 +
'''Constants''' are used to create a variable of a specified data type that can never be changed after declaration, all global variables should be declared constant. The only way to change it is to edit the code and re-compile.
 +
 
 +
<syntaxhighlight lang="csharp">const int example = 32</syntaxhighlight>

Latest revision as of 13:34, 11 June 2018

Video

https://www.youtube.com/watch?v=aJyx-CnfutI&list=PLCiOXwirraUCUY64UIv4NNx4losEKMJwd&t=4s&index=1

https://www.youtube.com/watch?v=heLqoaQVZEo&list=PLCiOXwirraUCUY64UIv4NNx4losEKMJwd&index=3

Intro

There are 9 types of data types. These include boolean, string, integer, double, decimal, character, byte, float and long:


Boolean is a binary value, being either true or false.

bool example = true;


String is used for storing characters in word form.

string example = "hello world";


Integer is used to store whole numbers (32 bit values).

int example = 457568368;


Double is used to store numbers where there are numbers before and after the decimal point, using 64 bits of memory.

double example = 3.3;


Decimal is used to store larger numbers with information before and after the decimal point, using 128 bits of memory.

decimal example = 12.593;


Character is used to store single letters.

char example = 'A';


Byte is used to store a byte (eight bits). In C#, it is specifically an 8 bit integer (0-255).

byte example = 255;


Float is used to store a 32 bit decimal number, which must be defined as being a float using "F" or "f" to distinguish it from a double, or it may cause compilation errors.

float example = 9.4F;


Long integer is also used to store whole numbers (However these are 64 bit values).

long example = 7846354759340276482;


Constants are used to create a variable of a specified data type that can never be changed after declaration, all global variables should be declared constant. The only way to change it is to edit the code and re-compile.

const int example = 32