当前位置:编程学习 > C#/ASP.NET >>

用C#风格写C++程序(探索C#对象模型)

写C#程序就是在设计一个类
先看一个C#程序(计算一个表达式):
[csharp]
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
 
namespace ConsoleApplicationCal 

    class Program 
    {  www.zzzyk.com
        private static char[,] Precede_Matrix = new char[7, 7] 
        { 
            {'>', '>', '<', '<', '<', '>', '>',}, 
            {'>', '>', '<', '<', '<', '>', '>',}, 
            {'>', '>', '>', '>', '<', '>', '>',}, 
            {'>', '>', '>', '>', '<', '>', '>',}, 
            {'<', '<', '<', '<', '<', '=', '0',}, 
            {'>', '>', '>', '>', '0', '>', '>',}, 
            {'<', '<', '<', '<', '<', '0', '=',} 
        }; 
 
        public static char Precede(char a, char b) 
        { 
            int i = 0; 
            int j = 0; 
            switch (a) 
            { 
                case '+': i = 0; break; 
                case '-': i = 1; break; 
                case '*': i = 2; break; 
                case '/': i = 3; break; 
                case '(': i = 4; break; 
                case ')': i = 5; break; 
                case '#': i = 6; break; 
                default: break; 
            } 
            switch (b) 
            { 
                case '+': j = 0; break; 
                case '-': j = 1; break; 
                case '*': j = 2; break; 
                case '/': j = 3; break; 
                case '(': j = 4; break; 
                case ')': j = 5; break; 
                case '#': j = 6; break; 
                default: break; 
            } 
 
            return (Precede_Matrix[i, j]); 
        } 
 
        public static double Operate(double a, char oper, double b) 
        { 
            switch (oper) 
            { 
                case '+': return a + b; 
                case '-': return a - b; 
                case '*': return a * b; 
                case '/': return a / b; 
                default: return -1; 
            } 
        } 
 
        public static bool IsOperand(char c) 
        { 
            if (('0' <= c && c <= '9') || c == '.')   //  c是数字或小数点 
                return true; 
            else 
                return false; 
        } 
 
        static void Main(string[] args) 
        { 
            string str; 
            while ((str = Console.ReadLine()) != null) 
            { 
                str += "#";                     //  最后是#(结束标志) 
 
                double a; 
                double b; 
     &n
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,