当前位置: 首页 > news >正文

做网站充值微信必须是企业安顺市住房与城乡建设局网站

做网站充值微信必须是企业,安顺市住房与城乡建设局网站,北京最新,哈尔滨网页网站制作一、接口概述 1.接口的概念 在C#中#xff0c;接口#xff08;interface#xff09;是一种引用类型#xff0c;它定义了一组方法、属性、事件或索引器#xff0c;但不提供实现。接口只定义成员的签名#xff0c;而具体的实现由实现接口的类或结构体提供。接口使用关键字…一、接口概述 1.接口的概念 在C#中接口interface是一种引用类型它定义了一组方法、属性、事件或索引器但不提供实现。接口只定义成员的签名而具体的实现由实现接口的类或结构体提供。接口使用关键字 interface 定义。 接口实例 public interface IShape {double GetArea();double GetPerimeter();string GetInfo(); }类实现接口实例 public class Circle : IShape {public double Radius { get; set; }public Circle(double radius){Radius radius;}public double GetArea(){return Math.PI * Radius * Radius;}public double GetPerimeter(){return 2 * Math.PI * Radius;}public string GetInfo(){return $Circle - Radius: {Radius}, Area: {GetArea():F2}, Perimeter: {GetPerimeter():F2};} }2.使用接口的好处 解耦和可替换性 接口定义了行为的契约而不关心具体的实现。这样代码依赖于接口而不是具体实现使得具体实现可以很容易地替换或修改而不影响使用接口的代码。 提高代码的可测试性 接口使得代码更容易进行单元测试。我们可以为接口创建模拟Mock对象测试代码可以使用这些模拟对象来独立验证逻辑而不需要依赖具体实现。 二、实例代码分析 1.Shapes.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace WpfApp {public interface IShape{double GetArea();double GetPerimeter();string GetInfo();}public class Circle : IShape{public double Radius { get; set; }public Circle(double radius){Radius radius;}public double GetArea(){return Math.PI * Radius * Radius;}public double GetPerimeter(){return 2 * Math.PI * Radius;}public string GetInfo(){return $Circle - Radius: {Radius}, Area: {GetArea():F2}, Perimeter: {GetPerimeter():F2};}}public class Rectangle : IShape{public double Width { get; set; }public double Height { get; set; }public Rectangle(double width, double height){Width width;Height height;}public double GetArea(){return Width * Height;}public double GetPerimeter(){return 2 * (Width Height);}public string GetInfo(){return $Rectangle - Width: {Width}, Height: {Height}, Area: {GetArea():F2}, Perimeter: {GetPerimeter():F2};}} } 2.MainWindow.xmal.cs using System; using System.Collections.Generic; // 用于 ListT using System.ComponentModel; // 用于 INotifyPropertyChanged 接口 using System.Windows; // 用于 WPF 相关类namespace WpfApp {public partial class MainWindow : Window{// 存储形状的列表ListIShape Shapes;// 存储形状信息的对象用于数据绑定private ShapeInfo MyShapeInfo;// 构造函数初始化组件和数据public MainWindow(){InitializeComponent();Shapes new ListIShape();MyShapeInfo new ShapeInfo();MyShapeInfo.Info ; // 初始化 Info 属性DataContext new { ShapeInfo MyShapeInfo }; // 设置数据上下文}// 添加圆形按钮的点击事件处理程序private void Button_Click_AddCircle(object sender, RoutedEventArgs e){double radius DateTime.Now.Second; // 使用当前秒数作为圆的半径Circle circle new Circle(radius); // 创建新的 Circle 对象Shapes.Add(circle); // 将 Circle 对象添加到列表中}// 添加矩形按钮的点击事件处理程序private void Button_Click_AddRectangle(object sender, RoutedEventArgs e){double height DateTime.Now.Second; // 使用当前秒数作为矩形的高度double width height / 2; // 使用当前秒数的一半作为矩形的宽度Rectangle rectangle new Rectangle(width, height); // 创建新的 Rectangle 对象Shapes.Add(rectangle); // 将 Rectangle 对象添加到列表中}// 显示形状信息按钮的点击事件处理程序private void Button_Click_ShowInfo(object sender, RoutedEventArgs e){string info ;// 遍历所有形状获取其信息foreach (IShape shape in Shapes){if (shape ! null){info shape.GetInfo(); // 获取形状信息info Environment.NewLine; // 添加换行符}}MyShapeInfo.Info info; // 更新 ShapeInfo 对象的 Info 属性ShapesInfo.Text MyShapeInfo.Info; // 更新 UI 中显示的信息}}// 用于存储和通知形状信息变化的类public class ShapeInfo : INotifyPropertyChanged{// 私有字段存储信息字符串private string _info;// 公有属性获取或设置信息字符串public string Info{get { return _info; }set{_info value;OnPropertyChanged(Info); // 通知属性值变化}}// 属性变化事件public event PropertyChangedEventHandler PropertyChanged;// 触发属性变化事件的方法protected virtual void OnPropertyChanged(string propertyName){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));}} }3.MainWindow.xmal Window x:ClassWpfApp.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlTitleShape Info Height350 Width525GridStackPanelButton ContentAdd Circle ClickButton_Click_AddCircle Margin10/Button ContentAdd Rectangle ClickButton_Click_AddRectangle Margin10/Button ContentShow Shapes Info ClickButton_Click_ShowInfo Margin10/TextBlock NameShapesInfo Margin10 FontSize16 TextWrappingWrap Text{Binding ShapeInfo.Info} //StackPanel/Grid /Window三、实验结果
http://www.tj-hxxt.cn/news/138602.html

相关文章:

  • 苏州市吴江区建设局网站潍坊市建设工程质量安全监督站网站
  • 门户类网站有哪些丽水做企业网站的地方
  • 做设计适合关注的网站如何查网站的备案信息
  • 个体营业执照可以做网站嘛php微信公众号开发教程
  • 看网站搜什么关键词网页传奇哪个最好玩
  • 重庆在百度做个网站多少钱一个做网站的团队需要哪些
  • 设计师品牌 网站wordpress 付费会员分类
  • 做视频的网站平台类网站有哪些
  • 域名怎么解析到网站如何制作自己的微信小程序
  • 网站空间管理地址dz 做企业网站
  • 长春模板网站建设企业wordpress谷歌广告代码
  • 南通建网站的公司如何用万网建设网站
  • 温州网站建设推广服务wordpress转typecho
  • 本地网站建设开发信息大全低价建设网站
  • 上海cms网站建设展厅设计图
  • 佛山网站免费制作网站被降权的原因
  • 个人网站做淘宝客会怎样p2p电影网站开发
  • 上海高端网站建设网站界面ui设计国家开放大学答案
  • 最爱网南京seo优化公司
  • 郑州网站设计 郑州网站开发手机优化大师怎么卸载
  • 推广公司的网站可以采取哪些方式怎样做农产品交易平台网站
  • 重庆祥云平台做网站坪地网站建设基本流程
  • 广州网站建设系统某网站开发工具和技术
  • 网站建设前台与后台最新技术wordpress分类页面添加幻灯片
  • 电子政务与网站建设 总结做水果网站需要些什么
  • 网站开发电脑配置网络架构图和拓扑图
  • 网站年龄和域名年龄重庆app制作开发商
  • 百度做网站的电话赛尔网络公司好不好
  • 网站不兼容360浏览器市场营销策略名词解释
  • 长沙多用户商城网站建设什么网站可以做平面设计赚钱