VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > C#教程 > c#编程 >
  • c#语法练习1 基本数据类型

制作者:剑锋冷月 单位:无忧统计网,www.51stat.net
  本例效果图:
 
  代码:
using System;


class MyClass

{

    static void Main()

    {

        Console.WriteLine("sbyte 类型:");

        sbyte sbyteVar = (sbyte.MaxValue + sbyte.MinValue) / 2;

        Console.WriteLine("{0}、{1}、{2} ", sbyte.MinValue, sbyteVar, sbyte.MaxValue);


        Console.WriteLine("byte 类型:");

        byte byteVar = (byte.MaxValue + byte.MinValue) / 2;

        Console.WriteLine("{0}、{1}、{2} ", byte.MinValue, byteVar, byte.MaxValue);


        Console.WriteLine("short 类型:");

        short shortVar = (short.MaxValue + short.MinValue) / 2;

        Console.WriteLine("{0}、{1}、{2} ", short.MinValue, shortVar, short.MaxValue);


        Console.WriteLine("ushort 类型:");

        ushort ushortVar = (ushort.MaxValue + ushort.MinValue) / 2;

        Console.WriteLine("{0}、{1}、{2} ", ushort.MinValue, ushortVar, ushort.MaxValue);


        Console.WriteLine("int 类型:");

        int intVar = (int.MaxValue + int.MinValue) / 2;

        Console.WriteLine("{0}、{1}、{2} ", int.MinValue, intVar, int.MaxValue);


        Console.WriteLine("uint 类型:");

        uint uintVar = (uint.MaxValue + uint.MinValue) / 2;

        Console.WriteLine("{0}、{1}、{2} ", uint.MinValue, uintVar, uint.MaxValue);


        Console.WriteLine("long 类型:");

        long longVar = (long.MaxValue + long.MinValue) / 2;

        Console.WriteLine("{0}、{1}、{2} ", long.MinValue, longVar, long.MaxValue);


        Console.WriteLine("ulong 类型:");

        ulong ulongVar = (ulong.MaxValue + ulong.MinValue) / 2;

        Console.WriteLine("{0}、{1}、{2} ", ulong.MinValue, ulongVar, ulong.MaxValue);


        Console.WriteLine("float 类型:");

        float floatVar = (float.MaxValue + float.MinValue) / 2;

        Console.WriteLine("{0}、{1}、{2} ", float.MinValue, floatVar, float.MaxValue);


        Console.WriteLine("double 类型:");

        double doubleVar = (double.MaxValue + double.MinValue) / 2;

        Console.WriteLine("{0}、{1}、{2} ", double.MinValue, doubleVar, double.MaxValue);


        Console.WriteLine("decimal 类型:");

        decimal decimalVar = (decimal.MaxValue + decimal.MinValue) / 2;

        Console.WriteLine("{0}、{1}、{2} ", decimal.MinValue, decimalVar, decimal.MaxValue);


        Console.WriteLine("char 类型:");

        char charVar = '万';

        Console.WriteLine("{0}、{1} ", charVar, ++charVar);


        Console.WriteLine("bool 类型:");

        bool boolVar = true;

        Console.WriteLine("{0}、{1} ", boolVar, !boolVar);


        Console.WriteLine("string 类型:");

        string stringVar = "万一的 Delphi 博客";

        Console.WriteLine("{0}、Length: {1} ", stringVar, stringVar.Length);


        Console.ReadKey();

    }


 


相关教程