Built-in types in C#
Built-in types in C#
- Boolean type: only true or false
- Integral types: sbyte, byte, short, ushort, int, uint, long, ulong, char
- Floating types: float and double
- Decimal types
- String type
using System; class Program { static void Main() { //boolean data type declaration bool b = true; Console.WriteLine(b); //Integral types Console.WriteLine("sbyte: min value: {0} , max value: {1}", sbyte.MinValue, sbyte.MaxValue); Console.WriteLine("byte: min value: {0} , max value: {1}", byte.MinValue, byte.MaxValue); Console.WriteLine("short: min value: {0} , max value: {1}", short.MinValue, short.MaxValue); Console.WriteLine("ushort: min value: {0} , max value: {1}", ushort.MinValue, ushort.MaxValue); Console.WriteLine("int: min value: {0} , max value: {1}", int.MinValue, int.MaxValue); Console.WriteLine("uint: min value: {0} , max value: {1}", uint.MinValue, uint.MaxValue); Console.WriteLine("long: min value: {0} , max value: {1}", long.MinValue, long.MaxValue); char ch = '%'; Console.WriteLine("char: {0}", ch); //Floating types Console.WriteLine("float: min value: {0} , max value: {1}", float.MinValue, float.MaxValue); Console.WriteLine("double: min value: {0} , max value: {1}", double.MinValue, double.MaxValue); //Decimal type decimal myMoney = 300.5m; Console.WriteLine(myMoney); } }
Output
Escape sequence in C#
When we need to print special characters like double quotes, backslash, etc. We can make use of the escape sequence as below:
using System; class Program { static void Main() { Console.WriteLine("\"Mayuresh Joshi\""); } }
Output
See all escape sequence characters available in C# here: https://devblogs.microsoft.com/csharpfaq/what-character-escape-sequences-are-available/
Verbatim Literal in C#
Strings starts with @ symbol are called as verbatim strings. Basically the @ symbol tells the string constructor to ignore escape characters and line breaks.
using System; class Program { static void Main() { string str = "\\Mayuresh\\TestFolder\\NewFolder"; Console.WriteLine(str); //using Verbatim Literal string str1 = @"\Mayuresh\TestFolder\NewFolder"; Console.WriteLine(str1); } }
Comments
Post a Comment