zoukankan      html  css  js  c++  java
  • 向string,int,类对象等中扩展方法

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 
     6 namespace ConsoleApplication1
     7 {
     8     class Program
     9     {
    10         static void Main(string[] args)
    11         {
    12             string s = "sss";
    13             s.Res();
    14             /**************************/
    15             student stu = new student("11013141","二货");
    16             stu.Say();
    17             stu.sayhello();
    18         }
    19     }
    20     /// <summary>
    21     /// 扩展方法写在一个静态类中
    22     /// </summary>
    23     public static class Test
    24     {
    25         public static void Res(this string s)
    26         {
    27             Console.WriteLine(s);
    28         }
    29         public static void sayhello(this student s)
    30         {
    31             Console.WriteLine(" 编号:" + s.No+";姓名:" + s.Name);
    32         }
    33     }
    34     public class student
    35     {
    36         //public student() { }
    37         public student(string no,string name)
    38         {
    39             this.No = no;
    40             this.Name = name;
    41         }
    42         private string no;
    43 
    44         public string No
    45         {
    46             get { return no; }
    47             set { no = value; }
    48         }
    49         private string name;
    50 
    51         public string Name
    52         {
    53             get { return name; }
    54             set { name = value; }
    55         }
    56         public void Say()
    57         {
    58             Console.WriteLine("姓名:"+Name+"; 编号:"+No);
    59         }
    60     }
    61 }
  • 相关阅读:
    vue $refs的用法
    .net 合并GridView中某列相同信息的行(方法1)
    vue 将编号转换成名字显示
    base64转图片的工具网站
    html +css + js 实现自定义模态框
    asp 弹窗效果
    vue 关于$emit的用法
    Git 合并分支
    asp 学习网站
    Tomcat部署方法
  • 原文地址:https://www.cnblogs.com/minotmin/p/3105370.html
Copyright © 2011-2022 走看看