Difference between revisions of "Data Type"

esse quam videri
Jump to: navigation, search
(Explanation)
 
(8 intermediate revisions by 3 users not shown)
Line 4: Line 4:
 
=Relevance=
 
=Relevance=
 
*[[Boolean]]
 
*[[Boolean]]
*[[Byte]]
 
 
*[[Character]]
 
*[[Character]]
 +
*[[Integer]]
 +
*[[Floating Point Number]]
 +
*[[Double]]
 
*[[Decimal]]
 
*[[Decimal]]
*[[Double]]
 
*[[Dynamic]]
 
*[[Floating Point Number]]
 
*[[Integer]]
 
*[[Long]]
 
*[[Short]]
 
 
*[[String]]
 
*[[String]]
*[[Var]]
 
  
 
=Explanation=
 
=Explanation=
 +
There are many different types of data types that are used for different tasks. Similar to a Mechanic using the right tool for the job, it is the job of the programmer to figure out which data type would be appropriate to use.
 +
 +
[[File:DataTypesVisual.png|512px]]
 +
 +
 
Information falls under a different data type. Different data types are used for different intents: for math you may use integers, floats, doubles, etc. while for keeping a contact list, strings would be more appropriate.  
 
Information falls under a different data type. Different data types are used for different intents: for math you may use integers, floats, doubles, etc. while for keeping a contact list, strings would be more appropriate.  
 
As mentioned before, data types limit which operations can be used on them. A string cannot be added to an integer because an integer can only be a whole number while a string can be a name, address, etc. However, an integer can be added to a string, this is known as [[Concatenation]]. It’s all about using the right data type for the right job.
 
As mentioned before, data types limit which operations can be used on them. A string cannot be added to an integer because an integer can only be a whole number while a string can be a name, address, etc. However, an integer can be added to a string, this is known as [[Concatenation]]. It’s all about using the right data type for the right job.
Line 23: Line 23:
  
 
[[File:Data types.PNG]]
 
[[File:Data types.PNG]]
 +
 +
Credits: https://www.tutorialsteacher.com/csharp/csharp-data-types
  
 
=Example=
 
=Example=
 
Here's an example of a few different types of variables being initialized along with a few [[Comment]]s
 
Here's an example of a few different types of variables being initialized along with a few [[Comment]]s
{| class="DataTable"
 
!
 
!
 
|-
 
|string name = “John Doe”;
 
|// strings are typically used to store information such as names, addresses, etc. because they can hold text.
 
|-
 
|string jobTitle = "Sales Associate";
 
|// notice how a string's value has the quotation marks!
 
|-
 
|bool isStudent= true;       
 
|// booleans can only be true or false. Great use in conditional statements!
 
|-
 
|int age = 20;                   
 
|// an int (short for integer) can only be a whole number. Since we typically say age as a whole number, we're using an int
 
|-
 
|float payrate= 12.50f;     
 
|// unlike integers, a float (short for floating-point number) can hold more complex numbers with decimal places. Great for displaying the example's payrate!
 
|-
 
|}
 
  
=Resources=
+
<syntaxhighlight lang ="csharp">
 +
string fullName = "John Doe";            // strings are typically used to store information such as names, addresses, etc. because they can hold text.
 +
string jobTitle = "Sales Associate";        // notice how a string's value has the quotation marks!
 +
bool isStudent= true;                    // booleans can only be true or false. Great use in conditional statements!
 +
int age = 20;                          // an int (short for integer) can only be a whole number. Since we typically say age as a whole number, we're using an int
 +
float payrate= 12.50f;                    // unlike integers, a float (short for floating-point number) can hold more complex numbers with decimal places. Great for displaying the example's payrate!
 +
</syntaxhighlight>
 +
 
 
== See also ==
 
== See also ==
 
* [[C Sharp Data Types]]
 
* [[C Sharp Data Types]]
Line 53: Line 42:
 
* [[.NET Data Types]]
 
* [[.NET Data Types]]
  
==Notes==
+
*[[Boolean]]
 +
*[[Byte]]
 +
*[[Character]]
 +
*[[Decimal]]
 +
*[[Double]]
 +
*[[Dynamic]]
 +
*[[Floating Point Number]]
 +
*[[Integer]]
 +
*[[Long]]
 +
*[[Short]]
 +
*[[String]]
 +
*[[Var]]
 +
 
  
  
==External Links==
 
  
  

Latest revision as of 16:22, 8 August 2019

Definition

A data type is an attribute of data that tells the compiler how the programmer intends on using the data. A data type limits the values that an expression might take.

Relevance

Explanation

There are many different types of data types that are used for different tasks. Similar to a Mechanic using the right tool for the job, it is the job of the programmer to figure out which data type would be appropriate to use.

DataTypesVisual.png


Information falls under a different data type. Different data types are used for different intents: for math you may use integers, floats, doubles, etc. while for keeping a contact list, strings would be more appropriate. As mentioned before, data types limit which operations can be used on them. A string cannot be added to an integer because an integer can only be a whole number while a string can be a name, address, etc. However, an integer can be added to a string, this is known as Concatenation. It’s all about using the right data type for the right job.

Here is a list of different data types available in C#

Data types.PNG

Credits: https://www.tutorialsteacher.com/csharp/csharp-data-types

Example

Here's an example of a few different types of variables being initialized along with a few Comments

string fullName = "John Doe";             // strings are typically used to store information such as names, addresses, etc. because they can hold text.
string jobTitle = "Sales Associate";         // notice how a string's value has the quotation marks!
bool isStudent= true;                    // booleans can only be true or false. Great use in conditional statements!
int age = 20;                           // an int (short for integer) can only be a whole number. Since we typically say age as a whole number, we're using an int
float payrate= 12.50f;                    // unlike integers, a float (short for floating-point number) can hold more complex numbers with decimal places. Great for displaying the example's payrate!

See also