C#学习总结

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

namespace HelloWorld
{
    struct Fraction1
    {
        public int numerator;
        public int denominator;
    }
    class Fraction
    {
        public int numerator;
        public int denominator;
    }
    class Program
    {
        static void Main(string[] args)
        {
            //testHelloWorld();
            //testBasicType();
            //testClass();
            //testCAL();
            //testif();
            //testifelse();
            //testStruct();
            //testswitch();
            //testfor();
            /*学习总结
             * 简单数据类型
             * 值和引用
             * 常量与变量
             * 表达示和运算符
             * 条件语句 if ..else /switch...c
             * 循环语句while/do..while/for
             * 跳转语句break/continue
             * 错误和异常处理
             */

        }

        private static void testWhile()
        {
            int i = 0;
            int sum = 0;
            while (i < 10)
            {
                i++;
                sum += i;
            }
            Console.WriteLine("{0}", sum);
        }
        private static void testWhiledo()
        {
            int i = 0;
            int sum = 0;
            do
            {
                i++;
                sum += i;
            } while (i < 10);
            Console.WriteLine("{0}", sum);
        }
        private static void testfor()
        {
            int sum = 0;
            for (int i = 0; i < 10;i++)
            {
                sum +=i;
            }
              
            Console.WriteLine("{0}", sum);
        }

        private static void testHelloWorld()
        {
            System.Console.WriteLine("Hello,World!");
        }

        private static void testStruct()
        {
            Fraction1 h;
            h.numerator = 3;//define struct
            h.denominator = 3;
            Console.WriteLine("h = {0}/{1}", h.numerator, h.denominator);
        }

        private static void testClass()
        {
            Fraction h = new Fraction();
            h.numerator = 3;
            h.denominator = 5;
            Console.WriteLine("h = {0}/{1}", h.numerator, h.denominator);
        }

        private static void testCAL()
        {
            const Char i = 'b';
            Console.WriteLine("i = {0}", i);
            Console.WriteLine("true && false:{0}", true && false);
            Console.WriteLine("true || false:{0}", true || false);
            int j = 0x000f0005, k = 0x00f0f003;
            Console.WriteLine("j = 0x{0:x8},k = 0x{0:x8}", j, k);
            Console.WriteLine("j = 0x{0:x8},k = 0x{0:x8}", ~j, ~k);
            Console.WriteLine("j&k = 0x{0:x8}", j & k);
            Console.WriteLine("j|k = 0x{0:x8}", j | k);
            Console.WriteLine("j^k = 0x{0:x8}", j ^ k);
            Console.WriteLine("17+5={0}/r/n17-5={1}/r/n17*5={2}/r/n17/5={3}/r/n17%5={4}", 17 + 5, 17 - 5, 17 * 5, 17 / 5, 17 % 5);
            Console.WriteLine("17 > 5={0}/r/n17>=5={1}/r/n17<5={2}/r/n17<=5={3}/r/n17==5={4}/r/n17!=5={5}", 17 > 5, 17 >= 5, 17 < 5, 17 <= 5, 17 == 5, 17 != 5);
            Console.WriteLine("2<<2={0}", 2 << 1);
        }

        private static void testBasicType()
        {
            short x = 32766;
            ushort y = 65534;
            Console.WriteLine("x = {0}", x);
            Console.WriteLine("y = {0}", y);
            x++;
            y++;
            Console.WriteLine("x = {0}", x);
            Console.WriteLine("y = {0}", y);
            x++;
            y++;
            Console.WriteLine("x = {0}", x);
            Console.WriteLine("y = {0}", y);
            bool a = true;
            bool b = false;
            Console.WriteLine("a = {0}", a);
            Console.WriteLine("b = {0}", b);

            float c = 3.1415926f;
            double d = 3.141519253579;
            Console.WriteLine("c = {0}", c);
            Console.WriteLine("d = {0}", d);
            c = (float)d;
            Console.WriteLine("c = {0}", c);
            decimal e = 1.23567894566m;
            e *= 2;
            Console.WriteLine("e = {0}", e);
            char f = '我';
            char g = 'A';
            Console.WriteLine("f = {0}", f);
            Console.WriteLine("g = {0}", g);
        }

        private static void testif()
        {
            if (2 > 1)
            {
                Console.WriteLine("2>1");
            }
        }
        private static void testswitch()
        {
            string fruit;
            //strng sTemp;
            //sTemp = Console.ReadLine;
            //iMark = Int32.Parse(sTemp);
            fruit = "apple";
            switch (fruit)
            {
                case "apple":
                    Console.WriteLine("I am an apple");
                    break;
                case "pineapple":
                    Console.WriteLine("I am a pineapple");
                    break;
                case "strawberry":
                    Console.WriteLine("I am a strawberry");
                    break;
                default:
                    Console.WriteLine("I am nothing");
                    break;
            }

        }
        private static void testifelse()
        {
            int iMark;
            //strng sTemp;
            //sTemp = Console.ReadLine;
            //iMark = Int32.Parse(sTemp);
            iMark = 100;
            if (iMark == 100)
            {
                Console.WriteLine("full");
            }
            else if (iMark >= 85)
            {
                Console.WriteLine("good");
            }
            else
            {
                Console.WriteLine("bad");
            }
        }
    }
}
 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值