1. 程式人生 > >C#代碼 Char、DateTime、轉義符、預定義引用

C#代碼 Char、DateTime、轉義符、預定義引用

nth 日期 string 取余 code tro 定義 get div

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
//以下為Char
char ch1 = ‘,‘;
Console.WriteLine(Char.IsSeparator(ch1));
char ch2 = ‘ ‘;
Console.WriteLine(Char.IsWhiteSpace(ch2));
Console.WriteLine(ch1.CompareTo(‘a‘));
string str1;
str1 = Char.ConvertFromUtf32(ch1);
Console.WriteLine(str1);
Console.WriteLine(Char.Equals(ch1, ch2));
Console.WriteLine(ch1.GetTypeCode());
char ch3 = ‘\a‘;
Console.WriteLine(Char.IsControl(ch3));
Console.WriteLine();

//以下為DateTime
DateTime dt1 = new DateTime(2018, 01, 04, 11, 20, 00);
DateTime dt2 = new DateTime(2018, 07, 04, 14, 20, 00);
Console.WriteLine(dt1.Date);//輸出當前時間精確到日期,不涉及幾點幾分幾秒
Console.WriteLine(dt1.DayOfWeek);//輸出當前時間是這一周的第幾天
Console.WriteLine(dt1.DayOfYear);//輸出當前時間是這一年的第幾天
Console.WriteLine(dt1.Hour);//輸出當前時間的點數
Console.WriteLine(System.DateTime.Now);//輸出當前時間,精確到秒
Console.WriteLine(System.DateTime.DaysInMonth(1998,2));//輸出在指定的年月中這個月有多少天
Console.WriteLine(DateTime.Now.Add(new TimeSpan(1008601, 0, 0)));//輸出指定時間間隔後的時間,時間間隔格式為時分秒
Console.WriteLine(DateTime.Parse("2018/01/04 11:20:00"));//輸出由字符串轉換成的時間
Console.WriteLine(dt1.ToLongDateString()+" "+dt1.ToLongTimeString());//輸出dt1的時間,精確到秒
Console.WriteLine(dt1.ToShortDateString() + " " + dt1.ToShortTimeString());//輸出dt1的時間,精確到分
TimeSpan ts1 = dt1-dt2;//設置一個時間間隔並輸出
Console.WriteLine(ts1);
Console.WriteLine(System.DateTime.Now + ts1);//輸出 當前時間加上一個特定的時間間隔後得到的時間
Console.WriteLine(ts1.Days+" "+ts1.Hours+" "+ts1.TotalDays);//間隔取整天、小時數對24取余、以天為單位的數
Console.WriteLine();

//以下為轉義字符
Console.WriteLine("衣阿華\‘級"+" "+"密蘇裏\"號"+" "+"MK7\\406毫米艦炮");
Console.WriteLine("\‘hello\‘");
Console.WriteLine("‘hello‘");
Console.WriteLine(@"‘hello‘");
Console.WriteLine();

//以下為引用類型
string str2 = "伊麗莎白女王級戰列艦";
string str3 = str2;
Console.WriteLine("str2:"+str2+" "+"str3:"+str3);
str2 = "沙恩霍斯特級戰列艦";
Console.WriteLine("str2:" + str2 + " " + "str3:" + str3);

Console.Read();
}
}
}

C#代碼 Char、DateTime、轉義符、預定義引用