""
把他包起来""
跟没有""
的差异吧!using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Program
{
static void Main(string[] args)
{
//宣告一个整数叫做 hi,然後赋予他100的值
int hi = 100;
//我们来列印看看
Console.WriteLine("我没有加双引号 : " + hi);
Console.WriteLine("我有加双引号 : " + "hi");
Console.ReadKey();
}
}
}
结果:
我没有加双引号 : 100
我有加双引号 : hi
""
的"hi"他是被当成文字的,没有""
的hi他则是整数变数,会直接印出他的值''
,而不是双引号""
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Program
{
static void Main(string[] args)
{
//宣告一个char型别的变数
char hi;
//先赋值A给变数hi,然後印出来
hi = 'A';
Console.WriteLine("1. " + hi);
//再来赋值B给变数hi,然後印出来
hi = 'B';
Console.WriteLine("2. " + hi);
//最後赋值C给变数hi,然後印出来
hi = 'C';
Console.WriteLine("3. " + hi);
Console.ReadKey();
}
}
}
结果:
- A
- B
- C
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Program
{
static void Main(string[] args)
{
//宣告一个string型别的变数
string hi;
//让电脑来个问候
hi = "安安,你好,几岁?住哪里?";
Console.WriteLine(hi);
//让电脑回答自己
hi = "你好,你是个好人,但我才不要告诉你勒";
Console.WriteLine(hi);
Console.ReadKey();
}
}
}
结果:
安安,你好,几岁?住哪里?
你好,你是个好人,但我才不要告诉你勒
Console.ReadLine()
这个函式using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Program
{
static void Main(string[] args)
{
//我们一开始使用Console.ReadLine()函式,让电脑听听我们的心声
//并将输入的名字赋值到字串变数中
string name = Console.ReadLine();
//接下来让电脑回答我们
Console.WriteLine(name + ",帅气十足!");
Console.ReadKey();
}
}
}
输入:
孤独一只鸡
结果:
孤独一只鸡
孤独一只鸡,帅气十足!
Console.Read()
这个函式注意:Console.Read()读出来会是字元的ASCII,所以会是整数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Program
{
static void Main(string[] args)
{
//我们使用Console.Read()函式,让电脑读取我们输入的字母
//电脑会自动将他转成ASCII编码
//并将ASCII编码赋值到变数中
int ch = Console.Read();
//印出输入字母的 ASCII
Console.WriteLine("The ASCII code is " + ch);
Console.ReadKey();
}
}
}
输入:
a
结果:
a
The ASCII code is 97
输入:
A
结果:
A
The ASCII code is 65
注:对於电脑而言,大写或小写甚至是任何符号,都有自己特有的编码所以我们这边输入大小写後会得到的结果
Convert.ToInt32()
这个函式Convert.ToInt32()这函式的用途,就是将其他型别转成整数型别,称为"转型"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Program
{
static void Main(string[] args)
{
//宣告半径为整数变数
int r;
//宣告圆面积为浮点数变数
double s;
//宣告圆周率为浮点数变数
double π = 3.1415926536;
//我们输入一个半径,并将输入的半径转成整数,赋值给变数r
Console.Write("r = ");
r = Convert.ToInt32(Console.ReadLine());
//计算面积 面积 = 圆周率 X 半径 X 半径
s = π * r * r;
//印出答案
Console.WriteLine("Ans:" + s);
Console.ReadKey();
}
}
}
输入:
5
结果:
r = 5
Ans:78.53981634
运算子"+"
,究竟会产生什麽样的爱恨纠葛呢?using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsharpDemo
{
class Program
{
static void Main(string[] args)
{
//宣告鸡
string chicken = "鸡";
//宣告鱼
string fish = "鱼";
//宣告狗
string dog = "象";
//宣告形容词
string lonely = "孤独一只";
//将他们做累加
Console.WriteLine(lonely + chicken);
Console.WriteLine(lonely + fish);
Console.WriteLine(lonely + dog);
Console.ReadKey();
}
}
}
结果:
孤独一只鸡
孤独一只鱼
孤独一只象
正确命名:
x
a1
myname
flowersCheckedListBox
_number
@float
错误命名:
8thStreet //不能以数字开头命名
float //不能和关键字同名
注意: C#区分大小写,比如name和Name是不同的变数,在为变数命名时,尽量选择有意义的名称。
<<: [Day2] Android - Kotlin笔记: lazy
[Day4] Web 小花花 不要问我为啥我的标题这麽傻白甜 我也不知道,取名好难 路上看到可爱小植...
Hello, 各位 iT邦帮忙 的粉丝们大家好~~~ 本篇是 Re: 从零开始用 Xamarin 技...
牛墟婆婆肉粽蛋饼(其实他没有店名@@) 地点:盐水区土库路(朝琴路右转一下子就到) 时间:早上 刚到...
本来想好好的喝杯咖啡,算了算了...结果被Allen一气,我先到了会议室...等下才开始,还是看一下...
重点整理 事件命名上必须使用小驼峰,且为 String 事件中必须放一个回传 Function re...