C#基础1——语法
2014-03-25 11:53
330 查看
C#基础1——语法
(一) .net ,visual studio , c# 之间的关系
![](http://hi.csdn.net/attachment/201203/4/0_1330850404A5r6.gif)
[align=left] [/align]
(二)VS开发环境的介绍
![](http://hi.csdn.net/attachment/201203/4/0_1330860582s1nO.gif)
[align=left] [/align]
(三)c#语法
![](http://hi.csdn.net/attachment/201203/4/0_13308606880diA.gif)
[align=left] [/align]
(二)c#程序
控制台的三条指令:
Console.WriteLine:打印输出
Console.ReadLine:从控制台读入一行
Console.ReadKey:控制台暂停。
例1:
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
Console.ReadKey(); //按一个按键继续执行
}
}
}
例2: Console.ReadLine应用
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
string s = Console.ReadLine();//用户输入文字的时候程序是暂停的,用户输入完毕点回车,把用户输入的东西作为返回值,声明一个string类型的变量(容器)s,用s来放WriteLine函数返回的值。
Console.WriteLine(s);
Console.ReadKey(); //按一个按键继续执行
}
}
}
例3:“+”,连接两个字符串
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
string s = Console.ReadLine();
Console.WriteLine(s+"你好");
int i1 = 10;
int i2 = 20;
Console.WriteLine(i1+"+"+i2+"="+(i1+i2));
Console.ReadKey();
}
}
}
例4:占位符的形式表示“i1+i2=i3”
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i1 = 10;
int i2 = 20;
//占位符从0开始,顺序就是WriteLine第二个参数开始的顺序
Console.WriteLine("{0}+{1}={2}",i1,i2,i1+i2); //占位符的形式表示
Console.ReadKey();
}
}
}
例4.2:
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入男孩的名字");
string boy = Console.ReadLine();
Console.WriteLine("请输入女孩的名字");
string girl = Console.ReadLine();
Console.WriteLine("{0}爱{1}",boy,girl);
Console.ReadKey();
}
}
}
例5:c#从上到下一条条依次执行
注意下面两段代码执行后第二次输出c的区别
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
a = 2;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
a = 2;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
a = 2;
c = a + j;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
a = 2;
c = a + j;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
例6:c#的注释
单行注释的表示:
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
a = 2;
Console.WriteLine(c); //此处很好的体现了“c#从上到下一条条依次执行
Console.ReadKey();
}
}
}
多行注释的表示
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
/*
Console.WriteLine("请输入男孩的名字");
string boy = Console.ReadLine();
Console.WriteLine("请输入女孩的名字");
string girl = Console.ReadLine();
Console.WriteLine("{0}爱{1}", boy, girl);
*/
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
string s = Console.ReadLine();//用户输入文字的时候程序是暂停的,用户输入完毕点回车,把用户输入的东西作为返回值,声明一个string类型的变量(容器)s,用s来放WriteLine函数返回的值。
Console.WriteLine(s);
Console.ReadKey(); //按一个按键继续执行
}
}
}
(一) .net ,visual studio , c# 之间的关系
![](http://hi.csdn.net/attachment/201203/4/0_1330850404A5r6.gif)
[align=left] [/align]
(二)VS开发环境的介绍
![](http://hi.csdn.net/attachment/201203/4/0_1330860582s1nO.gif)
[align=left] [/align]
(三)c#语法
![](http://hi.csdn.net/attachment/201203/4/0_13308606880diA.gif)
[align=left] [/align]
(二)c#程序
控制台的三条指令:
Console.WriteLine:打印输出
Console.ReadLine:从控制台读入一行
Console.ReadKey:控制台暂停。
例1:
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
Console.ReadKey(); //按一个按键继续执行
}
}
}
例2: Console.ReadLine应用
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
string s = Console.ReadLine();//用户输入文字的时候程序是暂停的,用户输入完毕点回车,把用户输入的东西作为返回值,声明一个string类型的变量(容器)s,用s来放WriteLine函数返回的值。
Console.WriteLine(s);
Console.ReadKey(); //按一个按键继续执行
}
}
}
例3:“+”,连接两个字符串
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
string s = Console.ReadLine();
Console.WriteLine(s+"你好");
int i1 = 10;
int i2 = 20;
Console.WriteLine(i1+"+"+i2+"="+(i1+i2));
Console.ReadKey();
}
}
}
例4:占位符的形式表示“i1+i2=i3”
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i1 = 10;
int i2 = 20;
//占位符从0开始,顺序就是WriteLine第二个参数开始的顺序
Console.WriteLine("{0}+{1}={2}",i1,i2,i1+i2); //占位符的形式表示
Console.ReadKey();
}
}
}
例4.2:
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入男孩的名字");
string boy = Console.ReadLine();
Console.WriteLine("请输入女孩的名字");
string girl = Console.ReadLine();
Console.WriteLine("{0}爱{1}",boy,girl);
Console.ReadKey();
}
}
}
例5:c#从上到下一条条依次执行
注意下面两段代码执行后第二次输出c的区别
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
a = 2;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
a = 2;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
a = 2;
c = a + j;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
a = 2;
c = a + j;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
例6:c#的注释
单行注释的表示:
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
a = 2;
Console.WriteLine(c); //此处很好的体现了“c#从上到下一条条依次执行
Console.ReadKey();
}
}
}
多行注释的表示
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
/*
Console.WriteLine("请输入男孩的名字");
string boy = Console.ReadLine();
Console.WriteLine("请输入女孩的名字");
string girl = Console.ReadLine();
Console.WriteLine("{0}爱{1}", boy, girl);
*/
int a = 3;
int j = 5;
int c = a + j;
Console.WriteLine(c);
Console.ReadKey();
}
}
}
[csharp] view
plaincopyprint?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
string s = Console.ReadLine();//用户输入文字的时候程序是暂停的,用户输入完毕点回车,把用户输入的东西作为返回值,声明一个string类型的变量(容器)s,用s来放WriteLine函数返回的值。
Console.WriteLine(s);
Console.ReadKey(); //按一个按键继续执行
}
}
}
相关文章推荐
- c#调用COM组件
- c#中虚函数的相关使用方法
- 浅析C# web访问mysql数据库-整理归纳总结
- C# IP地址与整数之间转换的具体方法
- C#中的多态深入理解
- C#实现的阴历阳历互相转化类实例
- C# 的关键字详细介绍
- c# 获得局域网主机列表实例
- C#基本概念列举详解
- C#中Convert.ToInt32()和int.Parse()的区别介绍
- C#面向对象特征的具体实现及作用详解
- c#静态方法和非静态方法详细介绍
- 关于C# Math 处理奇进偶不进的实现代码
- C#中调用Windows API的技术要点说明
- c# 随机函数的使用详解
- c#之圆形无标题栏椭圆窗体的实现详解
- C#页面之间跳转功能的小结
- 浅析C# 基础语法的使用
- C#中将字符串转换为整型的三种解决方法总结
- 深入c# GDI+简单绘图的具体操作步骤(一)