zoukankan      html  css  js  c++  java
  • C# 入门

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Retencle
        {
            double x;  // 浮点型
            int y;  // 整形
            string name;  // 字符串
            // 设置初始值
            public void settingValue()
            {
                x = 2.01;
                y = 4;
                name = "namejr";
            }
            // 计算面积
            public double area(){
                return x * y;
            }
            // 计算周长
            public double circle()
            {
                return 2 * x + 2 * y;
            }
            // 输出结束提示符
            public void showMessage()
            {
                double areaS = area();
                double cirC = circle();
                Console.WriteLine("名称: {0}", name);
                Console.WriteLine("周长: {0}", areaS);
                Console.WriteLine("面积: {0}", cirC);
                Console.Write("结束...");
                Console.ReadKey();
            }
        }
        // 调试输出函数
        class OutTest
        {
            public void setting(out int x, out int y)
            {
                x = 100;
                y = 125;
            }
        }
        // 引用传递
        class TestRef
        {
            public void test(ref double x, ref double y)
            {
                x = 2.002;
                y = 30.5;
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                /*
                 * 一个简单的计算面积周长公公式
                Retencle r = new Retencle();
                r.settingValue();
                r.showMessage();*/
                //
                // 查看字符类型的大小
                //Console.WriteLine(sizeof(int));
                //
                // 类型转换
                /*
                double s = 2.022;
                int i;
                i = (int)s;
                Console.WriteLine(i);
                 */
                // 类型转换方法
                /*
                string s;
                int i = 75;
                s = i.ToString();
                Console.Write(i);
                 */
                // 字符常量
                // Console.WriteLine("hello	worl
    d!!!");
                //
                /*
                // 使用out输出函数(后面关键字一节有提到)
                int a, b;
                OutTest t = new OutTest();
                t.setting(out a, out b);
                Console.WriteLine(a);
                Console.WriteLine(b);
                 */
                //
                //使用ref引用传递(后面关键字一节有提到)
                /*
                double s = 100.00;
                double c = 9.2;
                TestRef r = new TestRef();
                Console.WriteLine("未使用ref前:s({0}),c({1})", s, c);
                r.test(ref s, ref c);
                Console.WriteLine("使用ref后:s({0}),c({1})", s, c);
                 */
                //
                // 可空
                /*
                int? num1 = null;
                int? num2 = 123;
                double? num3 = new double?();
                double? num4 = 2.01;
                Console.WriteLine("{0}, {1}, {2}, {3}", num1, num2, num3, num4);
                 */
                //
                // 合并运算符,n不为空,如果“null ?? n”,那么结果为n;如果“notnull ?? n”,那么结果为notnull
                /*
                double? num1 = null;
                double? num2 = 2.35;
                double num3;
                num3 = num1 ?? 25.01;
                Console.WriteLine(num3);
                num3 = num2 ?? 12.00;
                Console.WriteLine(num3);
                 */
                Console.ReadKey();
            }
        }
    }

     注释:

    #define myName
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                #region
                // #region用来创建可折叠代码块,使用#endregion来进行判断
                // 下面的#if(条件)...#elif(条件)...#else...#endif是用来判断是否定义了符号字符
                // 定义符号字符可以使用#define
                #if(myName)
                    Console.WriteLine("myname is defined");
                #else
                    Console.WriteLine("myname is't defined");
                #endif
                #endregion
            }
        }
    }

    快捷键:

  • 相关阅读:
    mysql--SQL编程(关于mysql中的日期) 学习笔记2
    mysql--SQL编程(基础知识) 学习笔记1
    Geocoding java调用百度地图API v2.0 图文 实例( 解决102错误)
    java unicode转码为中文 实例
    spring hiberante 集成出现异常 java.lang.ClassNotFoundException: org.hibernate.engine.SessionFactoryImplementor
    [Spring学习笔记 7 ] Spring中的数据库支持 RowMapper,JdbcDaoSupport 和 事务处理Transaction
    [Spring学习笔记 6 ] Spring JDBC 详解
    ubuntu 连接windows远程桌面 &&rdesktop 退出全屏模式
    maven Missing artifact com.sun:tools:jar:1.5.0
    mysql 常用命令,连接数据库,查看建表语句,批量导入数据,批量更新数据,连接查询
  • 原文地址:https://www.cnblogs.com/namejr/p/10209533.html
Copyright © 2011-2022 走看看