JSRUN 用代码说话
using System;

public class HelloWorld
{
    public static void Main()
    {
       //程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。
        Console.WriteLine("HELLO JSRUN     - from C# ");
    }
}
celon(青春迷茫) - 2020-07-06 0 人
1.仿圆类创建长方形类(Rectangle,包括长...
using System;
using System.Collections.Generic;
using System.Text;

namespace FactoryMethod
{
    class Program
    {
        static void Main(string[] args)
        {
            IFactory operFactory = new AddFactory();
            Operation oper = operFactory.CreateOperation();
            oper.NumberA = 1;
            oper.NumberB = 2;
            double result=oper.GetResult();

            Console.WriteLine(result);

            Console.Read();
        }
    }
}
verniy(響) - 2020-06-03 0 人
Program
using System;
using System.Collections.Generic;
using System.Text;

namespace FactoryMethod
{
    /// <summary>
    /// 运算类
    /// </summary>
    class Operation
    {
        private double _numberA = 0;
        private double _numberB = 0;

        public double NumberA
        {
            get { return _numberA; }
            set { _numberA = value; }
        }

        public double NumberB
        {
            get { return _numberB; }
            set { _numberB = value; }
        }

        /// <summary>
        /// 得到运算结果
        /// </summary>
        /// <returns></returns>
        public virtual double GetResult()
        {
            double result = 0;
            return result;
        }
    }

    /// <summary>
    /// 加法类
    /// </summary>
    class OperationAdd : Operation
    {
        public override double GetResult()
        {
            double result = 0;
            result = NumberA + NumberB;
            return result;
        }
    }

    /// <summary>
    /// 减法类
    /// </summary>
    class OperationSub : Operation
    {
        public override double GetResult()
        {
            double result = 0;
            result = NumberA - NumberB;
            return result;
        }
    }
    /// <summary>
    /// 乘法类
    /// </summary>
    class OperationMul : Operation
    {
        public override double GetResult()
        {
            double result = 0;
            result = NumberA * NumberB;
            return result;
        }
    }
    /// <summary>
    /// 除法类
    /// </summary>
    class OperationDiv : Operation
    {
        public override double GetResult()
        {
            double result = 0;
            if (NumberB == 0)
                throw new Exception("除数不能为0。");
            result = NumberA / NumberB;
            return result;
        }
    }

    /// <summary>
    /// 工厂方法
    /// </summary>
    interface IFactory
    {
        Operation CreateOperation();
    }

    /// <summary>
    /// 专门负责生产“+”的工厂
    /// </summary>
    class AddFactory : IFactory
    {
        public Operation CreateOperation()
        {
            return new OperationAdd();
        }
    }

    /// <summary>
    /// 专门负责生产“-”的工厂
    /// </summary>
    class SubFactory : IFactory
    {
        public Operation CreateOperation()
        {
            return new OperationSub();
        }
    }

    /// <summary>
    /// 专门负责生产“*”的工厂
    /// </summary>
    class MulFactory : IFactory
    {
        public Operation CreateOperation()
        {
            return new OperationMul();
        }
    }

    /// <summary>
    /// 专门负责生产“/”的工厂
    /// </summary>
    class DivFactory : IFactory
    {
        public Operation CreateOperation()
        {
            return new OperationDiv();
        }
    }

}
verniy(響) - 2020-06-03 0 人
FactoryMethod
using System;

public class HelloWorld
{
    public static void Main()
    {
       //程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。
        Console.WriteLine("HELLO JSRUN     - from C# ");
    }
}
yulinlover(前端大神) - 2020-04-06 0 人
aaaaa
using System;

public class HelloWorld
{
    public static void Main()
    {
       //程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。
        Console.WriteLine("HELLO JSRUN     - from C# ");
    }

    public void Method1()
    {
        string str = "";
        for(int i = 0; i < 100; i++)
        {
            str += "test" + i;
        }
    }

    public void Method2()
    {
        string str = string.Format("{0},{1},{2}", "testA", "testB", "testC");
    }

    public void Method3()
    {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < 100; i++)
        {
            str.Append("test" + i);
        }
    }
    
    public void Method4()
        {
            var a0 = "User";
            var a1 = "Id";
            var a2 = 10086;
            var str = $"select * from {a0} where {a1}={a2}";
        }

}
zachary1986(此生不悔入华夏) - 2020-03-22 0 人
字符串拼接的各种方法: stringbuilde...
using System;

public class HelloWorld
{
    public static void Main()
    {
       //程序运行完成时一定要有输出语句,本工具才能正确展示运行结果。
        Console.WriteLine("HELLO JSRUN     - from C# ");
    }
}
xuenong(前端大神) - 2020-03-22 0 人
1.仿圆类创建长方形类(Rectangle,包括长...
没有了
1/4 下一页