2017.6.26 C# 無痛學習 筆記
紀錄時間: 1920~2157
const double PI = 3.14159 //PI在程式中為常數,不可改變
注意命名不能用C#的關鍵字
int c = 42 //int 花 4bytes 記憶體
short int c = 42 //short int 只花 2bytes
Unsigned integral 無負號的整數,EX: bytes, uint etc.
boolean 0為false, 非0為true, EX: bool num = -43 //true
char 可用\x 16進位 or \u unicode
*************************struct的應用**********************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3
{
class Program
{
struct person
{
public string name;
public float salary;
public int age, height;
public bool alive;
}
struct person1
{
//struct "person" gots Joe's base info
public person Joe;
public string handsome;
}
static void Main(string[] args)
{
person1 person_one;
person_one.Joe.salary = 47325.53f;
person_one.Joe.age = 26;
person_one.Joe.height = 181;
person_one.Joe.alive = true;
person_one.handsome = "Yes!"; //beware "handsome" variable is in person1 struct
Console.WriteLine("Name: {0}", person_one.Joe.salary);
Console.WriteLine("Salary: {0}", person_one.Joe.age);
Console.WriteLine("Age: {0}, height: {1}", person_one.Joe.age, person_one.Joe.height);
Console.WriteLine("Alive? {0}", person_one.Joe.alive);
Console.WriteLine("handsome? {0}", person_one.handsome);
Console.Read();
}
}
}
*********************************************************************************
const double PI = 3.14159 //PI在程式中為常數,不可改變
注意命名不能用C#的關鍵字
int c = 42 //int 花 4bytes 記憶體
short int c = 42 //short int 只花 2bytes
Unsigned integral 無負號的整數,EX: bytes, uint etc.
boolean 0為false, 非0為true, EX: bool num = -43 //true
char 可用\x 16進位 or \u unicode
*************************struct的應用**********************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3
{
class Program
{
struct person
{
public string name;
public float salary;
public int age, height;
public bool alive;
}
struct person1
{
//struct "person" gots Joe's base info
public person Joe;
public string handsome;
}
static void Main(string[] args)
{
person1 person_one;
person_one.Joe.salary = 47325.53f;
person_one.Joe.age = 26;
person_one.Joe.height = 181;
person_one.Joe.alive = true;
person_one.handsome = "Yes!"; //beware "handsome" variable is in person1 struct
Console.WriteLine("Name: {0}", person_one.Joe.salary);
Console.WriteLine("Salary: {0}", person_one.Joe.age);
Console.WriteLine("Age: {0}, height: {1}", person_one.Joe.age, person_one.Joe.height);
Console.WriteLine("Alive? {0}", person_one.Joe.alive);
Console.WriteLine("handsome? {0}", person_one.handsome);
Console.Read();
}
}
}
*********************************************************************************
留言
張貼留言