顾乔芝士网

持续更新的前后端开发技术栈

C#编程显示特定的日期格式,并且计算当前日期的前后日期源代码

使用C#编程显示特定的日期格式,并且计算当前日期的前后日期

界面:

源代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            inirq();
        }
        private string str_rq;
        private void inirq()
        {
            comboBox1.Items.Add("2001/1/1");
            comboBox1.Items.Add("2001年1月");
            comboBox1.Items.Add("2001年1月1日");
            comboBox1.Items.Add("2001年1月1日 00:00");
            comboBox1.Items.Add("2001年1月1日 00:00:00");
            comboBox1.Items.Add("自定义格式");
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(comboBox1.SelectedIndex==0)
            {
                str_rq = "d";
            }
            else if (comboBox1.SelectedIndex == 1)
            {
                str_rq = "y";
            }
            else if (comboBox1.SelectedIndex == 2)
            {
                str_rq = "D";
            }
            else if (comboBox1.SelectedIndex == 3)
            {
                str_rq = "f";
            }
            else if (comboBox1.SelectedIndex == 4)
            {
                str_rq = "F";
            }
            else if (comboBox1.SelectedIndex == 5)
            {
                str_rq = "yyyy年MM月dd日 HH时mm分ss秒";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = DateTime.Now.ToString(str_rq);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            texToday.Text = DateTime.Now.ToString("D");
            texYesterday.Text = DateTime.Now.AddDays(-1).ToString("D");
            texTomorrow.Text = DateTime.Now.AddDays(1).ToString("D");
        }
    }
}

CommunityToolkit.Mvvm:ObservableProperty 属性生成器深度解析

什么是ObservableProperty?

ObservableProperty是CommunityToolkit.Mvvm提供的一个强大属性生成器,它能够:

  • 自动生成属性变更通知
  • 减少样板代码
  • 提供编译时代码生成

c# 10 教程:24 本机和 COM 互操作性


本章介绍如何与本机(非托管)动态链接库 (DLL) 和组件对象模型 (COM) 组件集成。除非另有说明,否则本章中提到的类型存在于 System 或 System.Runtime.InteropServices 命名空间中。

干掉 BeanUtils!这款 Bean 自动映射神器出 Spring 插件了

之前安利过Mapstruct 这个神器,它可以代替

BotSharp + MCP 三步实现智能体开发

跟着官网学ASP.NET Core 6.0之请求参数模型验证

前面,我们学习了模型绑定,这一节,我们继续跟着官网来学习一下模型验证,一般情况下,我们需要对传入的参数进行校验,常规操作一般是通过if来对每一个需要校验的参数进行判断,在使用模型之后,我们便可以借助

[西门子PLC] C#通过modbus tcp与S7-200 smart通信测试

一、编写S7-200 Smart的MODBUS TCP SERVER程序段

首先调用库文件

使用C#上位机winform读写西门子S7-200SMART的IO信号

概述

本文采用winform制作上位机画面,通过西门子S7通信(S7.net)访问西门子PLC S7-200SMART的IO信号,实现简单的读写操作。

1 配置

1.1硬件要求

PC 操作电脑

CPU ST30 (6ES7288-1ST30-0AA1)

1.2软件要求

CommunityToolkit WinForms中的数据绑定:实现界面与对象双向同步

在 C# 开发中,INotifyPropertyChanged 接口在实现 MVVM(Model-View-ViewModel)模式时至关重要。它允许视图(UI)在后台数据发生变化时自动更新,从而实现数据绑定和界面同步。本文将详细介绍如何实现 INotifyPropertyChanged 接口,并利用 CommunityToolkit.Mvvm 库简化开发过程。

什么是 INotifyPropertyChanged 接口

干掉 BeanUtils!试试这款 Bean 自动映射工具,真心强大


public interface MemberMapper {
    MemberMapper INSTANCE = Mappers.getMapper(MemberMapper.class);

    @Mapping(source = "member.phone",target = "phoneNumber")
    @Mapping(source = "member.birthday",target = "birthday",dateFormat = "yyyy-MM-dd")
    @Mapping(source = "member.id",target = "id")
    @Mapping(source = "order.orderSn", target = "orderSn")
    @Mapping(source = "order.receiverAddress", target = "receiverAddress")
    MemberOrderDto toMemberOrderDto(Member member, Order order);
}
复制代码
<< 1 2 3 > >>
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言