将数值转换为大写的方法

> 使用自定义方法实现基本的整数转大写

    
    	class Program
    	{
    		static string[] units = { "", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
    		static string[] chineseUnits = { "", "拾", "佰", "仟" };
    
    		static string NumberToChinese(int number)
    		{
    			if (number == 0)
    			{
    				return "零";
    			}
    			string result = "";
    			int unitIndex = 0;
    			while (number > 0)
    			{
    				int digit = number % 10;
    				if (digit!= 0)
    				{
    					result = units[digit] + chineseUnits[unitIndex] + result;
    				}
    				else if (result.Length > 0 && result[0]!= '零')
    				{
    					result = "零" + result;
    				}
    				number /= 10;
    				unitIndex++;
    			}
    			return result;
    		}
    
    		static void Main()
    		{
    			int number = 1234;
    			Console.WriteLine(NumberToChinese(number));
    		}
    	}
    
    				

C# 中计算二维平面坐标距离

> 二维平面坐标距离(使用勾股定理)


	using System;

	class Program
	{
		// 计算二维平面上两点之间的距离
		static double CalculateDistance2D(double x1, double y1, double x2, double y2)
		{
			double deltaX = x2 - x1;
			double deltaY = y2 - y1;
			double distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY);
			return distance;
		}

		static void Main()
		{
			double x1 = 1;
			double y1 = 2;
			double x2 = 4;
			double y2 = 6;
			double distance2D = CalculateDistance2D(x1, y1, x2, y2);
			Console.WriteLine("二维平面上两点之间的距离: " + distance2D);
		}
	}