C# Tutorial Footage No.2 [Conversion of Values]

original exercises found here in Japanese. https://ufcpp.net/study/csharp/exercise.html#1192

Task1: show the character code of any character typed into the console

- note that in order to get the very first letter from console input you - need to set the index[0] after the Console.Readline()
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.Write("This program tells you the character code of any 1 character\n");
Console.Write("Enter 1 character \n");
// get the very first letter of console input
char chara = Console.ReadLine()[0];
// show the result on console
Console.Write("the character code ASCII[decimal] of {0} is {1}\n", chara, (int)chara);
}
}
}
view raw gistfile1.txt hosted with ❤ by GitHub

Task2: compare divisions are evaluated differently with different value types such as integer types and floating point number types

SKIPPED!!!

Task3: Observe how double type numbers are round up or round down

using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.Write("This program casts doubles into integers \n");
Console.Write("{0} => {1}\n", 1.2, (int)1.2);
Console.Write("{0} => {1}\n", 0.8, (int)0.8);
Console.Write("{0} => {1}\n", -1.2, (int)-1.2);
Console.Write("{0} => {1}\n", -0.8, (int)-0.8);
}
}
}
view raw gistfile1.txt hosted with ❤ by GitHub

コメント

このブログの人気の投稿

C# Tutorial Footage No.1