Uploaded by Sai Y

C# Tutorial

advertisement
C# Tutorial
Reading and writing to a console
Code samples used in the demo
using System;
class Program
{
static void Main()
{
// Prompt the user for his name
Console.WriteLine("Please enter your name");
// Read the name from console
string UserName = Console.ReadLine();
// Concatenate name with hello word and print
Console.WriteLine("Hello " + UserName);
//Placeholder syntax to print name with hello word
//Console.WriteLine("Hello {0}", UserName);
}
}
Please note that C# is case sensitive language.
Built-in Datatypes
Built-in types in C#
1. Boolean type – Only true or false
2. Integral Types - sbyte, byte, short, ushort, int, uint, long, ulong, char
3. Floating Types – float and double
4. Decimal Types
5. String Type
Refer to datatypes
https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/numbers-in-csharp
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-types
https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/branches-and-loops
https://docs.microsoft.com/en-us/learn/paths/csharp-first-steps/
https://docs.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
https://docs.microsoft.com/en-us/learn/modules/csharp-basic-operations/
https://docs.microsoft.com/en-us/learn/browse/?products=dotnet
Verbatim Literal is a string with an @ symbol prefix, as in @“Hello”. Verbatim literals make escape sequences translate as normal printable characters to
enhance readability.
using System;
namespace ConsoleApplication1
{
class Program
{
public static void Main()
{
// Displaying double quotes in c#
string Name = "\"Pragim\"";
Console.WriteLine(Name);
// Displaying new line character in c#
Name = "One\nTwo\nThree";
Console.WriteLine(Name);
// Displaying new line character in c#
Name = "c:\\Pragim\\DotNet\\Training\\Csharp";
Console.WriteLine(Name);
// C# verbatim literal
Name = @"c:\Pragim\DotNet\Training\Csharp";
Console.WriteLine(Name);
}
}
}
Download