初识c#

考研之后本来打算进公司学习点工作经验 和小伙伴相约投简历去苏州 几经思考 觉得不靠谱 正好在学校的童鞋说放假可以提前去实习 明年就不用去了 就来*州**公司 这个公司才和学校签约 规模不小 集培训、研发一体,我们学的是VR+游戏开发 还有大数据、Java h5 UI等几个方向 Unity学了三天做了坦克飞机大战 只是皮毛 就不给学了 先开始学语言 奈何教的太基础 中间思绪乱飞 就想着整理一下博客 以下先发一些基础知识 各个语言都有相似和独特之处 有语言基础的可融会贯通 供初学者和自己复习

using System;//使用系统工具

namespace FirstProject//命名空间
{
	class MainClass//主类 类:一些拥有相同方法和属性的事物的集合
	{   // 类中包含方法和属性 
		public static int age;//属性(即变量) 修饰符public/private省略则默认为后者
		//在静态函数中需要使用static定义的变量 若age不加 则报错
		public static void Main (string[] args)//主类方法(一个算法); main 方法名; 
		//string args[] 函数的参数 args为数组名
		{//公共类 私有类private  保护类 静态类static(属性也需是静态)  
			Console.WriteLine ("Hello World!");
			//Console.WriteLine (args);
			age = 2;//变量赋值时只能定义时或者方法(函数)中 方法外报错;
			Console.WriteLine (age);
			//调用另一个类的变量 两种方法:1 创建一个类的对象 用对象调属性
			MyClass zhangsan=new MyClass ();   
			Console.WriteLine (zhangsan.weight);
			//2 静态共有属性可以直接用类名调用
			Console.WriteLine(MyClass.sex);
			Console.WriteLine("1");//换行输出
			Console.Write("1");//不换行输出

			string str = Console.ReadLine ();//读取控制台的输入一串string 回车结束
			Console.WriteLine(str);
			int value = Console.Read ();//读取输入 一个整数 int(string型不可)
			Console.WriteLine(value);//键码值keycode(输入8 对应56)

			for(int i=0;i<9;i++)
			{

			}
			while (1 < 2)
			{
				break;
			}

			int a = 3;
			if(a==3)
			{
				
			}
			else if()
			{
				
			}
			switch(a)
			{
			case 1:
				{
					
				}
			case 2:
				{
					
				}
			}
            
				 
		}
	}
	class MyClass//自定义新的类
	{
		private float height = 165f;//float类型后加 f 表示小数
		public float weight= 50f;//共有类可在其他类调用 私有类只在本类调用
		public static bool sex=true;//静态共有属性可直接调用
			

	}
} 

/*
 int 4个字节\long 8\long long 8\ float 4\double 8\char 1\string 
 byte 字节类型 1个字节
 bool 布尔类型 判断 1个字节
*/





//四则运算,加法
//			result1=(int) (a+b);           //float 转int.
//			Console.WriteLine(result1);    //输出语句
//			Console.WriteLine("请输入字符");
//			c = Console.Read();           //Console.Read()读出键码值
//			Console.WriteLine(c);
//			//上程序一
//			Console.WriteLine("输入第一个数");  
//			str1 = Console.ReadLine ();   //输入语句,字符串
//			Console.WriteLine("输入第二个数");
//			str2 = Console.ReadLine ();
//			result2 = int.Parse (str1) * int.Parse (str2);//字符串型转int型
//			Console.WriteLine("str1*str2="+ result2);
//			str1 = result2.ToString ();              //数字类型转字符串
//   		Console.WriteLine("str1*str2="+ str1 );
//			//上程序二

以下的更为结构清晰、、、


using System;

namespace Day2
{
	class MainClass
	{
		//注释键:
		//vs :
		//注释键:Ctrl + K + C
		//取消注释键: Ctrl + K + U
		//Ctrl + z 后退键/撤销键


		//变量
		/*
		 * 变量类型
		 * 整数类型 没有小数点的整数 int  
		 * 单精度浮点类型 有一定数量的小数点位数 float 值后面加小写f
		 * 双精度浮点类型 拥有比单精度更多位数的小数点 double
		 * 布尔类型     	答案只有两种    true  FALSE    bool
		 * 字符类型      单个         char     ''
		 * 字符串类型		由多个字符组成的一句话   string  ""
		 * 
		 * 
		 * 
		*/

		//定义变量
		/*
		 * 定义在哪
		 * 第一种:类里面(类名后面的大括号里面),方法外面
		 * 大括号的作用:划定范围
		 * 怎么定义:
		 * 访问修饰符 + 变量类型 + 变量名 + ;
		 * 如果你想要把一个变量在控制台上显示,你必须有输出,才能显示
		 * 变量的赋值
		 * 	
		*/


		/*
		int 取值范围-2,147,483,648 到 2,147,483,647
		float是单精度类型,精度是6位有效数字,取值范围是10的-38次方到10的38次方,float占用4个字节的存储空间 
		double是双精度类型,精度是15位有效数字,取值范围是10的-308次方到10的308次方,double占用8个字节的存储空间 
		*/



		//		public static int number = 40 ;//int 类型的变量默认值是0    int 取值范围-2,147,483,648 到 2,147,483,647
		//		public  static float money = 12.1f;//float 类型的变量默认值是0  取值范围  2^(-149)~~(2-2^(-23))*2^127, 精度7位,可保证6位
		//		public static double height = 12.0;//double 类型的变量默认值是0
		//
		//		public static bool isHaveMoney = true;//bool 类型的变量默认值是FALSE
		//		public static char word  = 'A';//char 默认是是空
		//		public static string lagu = "中文";//string 默认是是空
		//			 1 + 1 = 2
		//

		public static float a = 2.3f;
		public static float b = 3.1f;

		public static int result1;
		public static float result2;
		public static string result3;
		public static string str1;
		public static string str2 ;

		public static void Main (string[] args)
		{

			//读取你输入的一个字符串
			//加法运算的小程序
			Console.WriteLine ("请输入第一个数:");
			str1 = Console.ReadLine ();//这个方法会返回一个字符串,如果这个字符串符合数字类型的结构,咱们可以把这个字符串转换成数字类型进行计算
			Console.WriteLine ("请输入第二个数:");
			str2 = Console.ReadLine ();


			result1 = int.Parse (str1) * int.Parse (str2);
			Console.WriteLine ("最终结果:");
			Console.WriteLine (2*3);

			Console.ReadLine ();





			//Console.WriteLine (result1);
			//数字类型转成string类型
			// 1,"1"
			//			result3 = result1.ToString();
			//			result3 = result2.ToString ();




			//string类型转化成数字类型
			//			result1 = int.Parse(str);
			//			Console.WriteLine (result1);
			//




			//Console.WriteLine (39);
			//Console.WriteLine ("2");
			//			Console.WriteLine (number);
			//			Console.WriteLine ("number");
			//			Console.WriteLine (money);
			//			Console.WriteLine (height);
			//			Console.WriteLine (isHaveMoney);
			//Console.WriteLine (word);
			//Console.WriteLine (lagu);

			//加法运算

			//			result	= (int)(a + b);
			//			Console.WriteLine (result);
			//
			//减法运算
			//			result = a - b;
			//			Console.WriteLine (result);

			//乘法运算
			//			result = a * b;
			//			Console.WriteLine (result);
			//

			//除法运算 / 只取商
			//result = a / b;//取得是a除以b的商
			//Console.WriteLine (result);

			//result = a % b;//取得是a除以b的余数


			//Console.WriteLine (result);


			//类型的转换分成两种:
			//显式转换 (转换成的变量类型)手动转换 float 转成int 
			//隐式转换 系统自动完成转化 int 转成 float
			//精度高的像精度低的:显式转换 手动去转
			//精度低的向精度高的:隐式转换,系统自己转,咱们不用管

			//转成int类型  (转换成的变量类型)
			//			result1 = (int)a;
			//			Console.WriteLine (result1);
			//			result2 = result1;
			//
			//string 转换成 int/float/double
			// "23.1","张三"

		}

	}
}



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值