Understanding Boolean, Integer, Double, Char, and String Declarations in Programming
This guide outlines how to declare and initialize various data types in programming, focusing on Boolean, Integer, Double, Char, and String types. It explains the preferred types for each category, offers examples of initialization, and demonstrates how to output values using console commands. Understanding these fundamental data types helps in effective programming and provides the foundation for more complex coding concepts. Ideal for beginners and those looking to refresh their programming skills.
Understanding Boolean, Integer, Double, Char, and String Declarations in Programming
E N D
Presentation Transcript
Variables Mr. McTavish
How to Declare boolblBoolean; – or – Boolean blBoolean2; Boolean is the preferred type.
How to Initialize blBoolean = true; – or – blBoolean2 = false;
How to Declare intintInteger; – or – Int32 intInteger2; Int32 is the preferred type
How to Initialize intInteger = -7; – or – intInteger2 = 3764;
How to Declare doubledblDouble; – or – Double dblDouble2; Double is the preferred type
How to Initialize dblDouble = 3.01; – or – dblDouble2 = 1;
Output //Declare and initialize DoubledblPrice = 3.1; //Outputs as dollar Console.WriteLine(dblPrice.ToString("$0.00"));
How to Declare charchrChar; – or – Char chrChar2; Note: Char is the preferred type
How to Initialize chrChar = 'a'; – or – chrChar2 = 'Z'; Note the single quotation marks
How to Declare stringstrString; – or – String strString2; Note: String is the preferred type
How to Initialize strString = "Hello"; – or – strString2 = "A String";