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

杭州好的做网站公司网站优化外包找谁

杭州好的做网站公司,网站优化外包找谁,买了个网站后怎么做,专做水果的社区网站文章目录 题目 1: 泛型类题目 2: 泛型方法题目 3: 泛型接口题目 4: 泛型约束题目 5: 泛型集合题目6:题目7:题目8:题目9: 题目 1: 泛型类 编写一个泛型类 Box,它能够存储一个类型为 T 的值,并提供方法 SetI…

文章目录

    • 题目 1: 泛型类
    • 题目 2: 泛型方法
    • 题目 3: 泛型接口
    • 题目 4: 泛型约束
    • 题目 5: 泛型集合
    • 题目6:
    • 题目7:
    • 题目8:
    • 题目9:

题目 1: 泛型类

编写一个泛型类 Box,它能够存储一个类型为 T 的值,并提供方法 SetItem 和 GetItem 来设置和获取该值并给出使用示例。

 public class Program{public class Box<T> {private T _item;public void SetItem(T item){_item= item;}public T GetItem(){return _item;}}static void Main(string[] args){Box<int> intbox = new Box<int>();intbox.SetItem(123);Console.WriteLine(intbox.GetItem());Box<string> stringbox = new Box<string>();stringbox.SetItem("Hello");Console.WriteLine(stringbox.GetItem());}}

题目 2: 泛型方法

编写一个泛型方法 Swap,它接受一个数组和两个索引,交换数组中这两个位置的元素,并给出使用示例。

public static void Swap<T>(T[] array,int index1,int index2){T temp = array[index1];array[index1] = array[index2];array[index2] = temp;}static void Main(string[] args){int[] numbers = { 1, 2, 3, 4, 5, 6 };foreach(var number in numbers){Console.Write(number);}Swap(numbers, 0, 5);Console.WriteLine();foreach(var number in numbers){Console.Write(number);}}

题目 3: 泛型接口

定义一个泛型接口 IRepository,它包含两个方法:Add 和 Get。Add 方法用于添加类型 T 的对象,Get 方法用于获取类型 T 的对象,并给出使用示例。

public class Program{public interface IRepository<T>{public void Add(T value);public T Get();}public class SampleClass:IRepository<int>{private int t;public void Add(int value){t=value;}public int Get(){return t;}}static void Main(string[] args){IRepository<int> repository = new SampleClass();repository.Add(1);Console.WriteLine(repository.Get());}}

题目 4: 泛型约束

编写一个泛型方法 PrintTypeName,它接受一个泛型参数 T 并打印 T 的类型名称。要求使用泛型约束来确保 T 是一个引用类型,并给出使用示例。

public class Person{public int Age { get; set; }public string Name { get; set; }}public class Program{public static void PrintTypeName<T>(T t)where T : class{Console.WriteLine($"Type Name:{typeof(T).Name}");}static void Main(string[] args){PrintTypeName("Hello,world");PrintTypeName(new Person());}}

题目 5: 泛型集合

创建一个泛型列表 MyList,它支持添加和移除元素,并且可以遍历列表中的元素,并给出使用示例。

    public class Program{public class MyList<T>{public List<T> list=new List<T>();public void Add(T item){list.Add(item);}public void RemoveAt(int item){list.RemoveAt(item);}public void Foreach(){foreach(var item in list){Console.WriteLine(item);}}}static void Main(string[] args){MyList<int>mylist=new MyList<int>();mylist.Add(1);mylist.Add(2);mylist.Add(3);mylist.Foreach();mylist.RemoveAt(0);mylist.Foreach();}}

题目6:

编写一个拓展方法 Filter,扩展 IEnumerable,接收一个 Func<T, bool> 作为参数,并返回一个仅包含符合条件的元素的集合。要求实现一个简单的筛选功能,比如筛选出集合中的所有偶数。

public static class IEnumerableExtensions{public static IEnumerable<T> Filter<T>(this IEnumerable<T> source, Func<T, bool> predicate){foreach(T item in source){if (predicate(item)){yield return item;}}}}class Program{static void Main(string[] args){IEnumerable<int> numbers = new List<int> { 1, 2, 3, 4, 5, 6 };IEnumerable<int> evenNumbers = numbers.Filter(n => n % 2 == 0);foreach(int n in evenNumbers){Console.WriteLine(n);}}}

题目7:

创建一个包含事件 OnValueChanged 的类 Notifier。定义一个委托 ValueChangedHandler,用于处理 OnValueChanged 事件。然后在主程序中,创建 Notifier 实例并订阅事件,当事件被触发时打印一条消息。

{public delegate void ValueChanedHandler(Object sender,EventArgs args);public class Notifier{public event ValueChanedHandler OnValueChaned;protected virtual void OnValueChangedEvent(){OnValueChaned?.Invoke(this, EventArgs.Empty);}public void TriggerValueChaned(){OnValueChangedEvent();}}class Program{static void Main(string[] args){Notifier notifier= new Notifier();notifier.OnValueChaned += Notifier_OnValueChanged;notifier.TriggerValueChaned();Console.ReadKey();}private static void Notifier_OnValueChanged(object sender, EventArgs args){Console.WriteLine("Value changed event triggered.");}}}

题目8:

定义一个委托 Printer,可以处理输出字符串的方法。创建两个方法 PrintUpperCase 和 PrintLowerCase,分别将字符串转换为大写和小写。然后,创建一个多播委托,先调用 PrintUpperCase,再调用 PrintLowerCase。

public delegate void Printer(string message);class Program{public static void PrintUpperCase(string message){Console.WriteLine(message.ToUpper());}public static void PrintLowerCase(string message){Console.WriteLine(message.ToLower());}static void Main(string[] args){Printer printUpperCaseDelegate = PrintUpperCase;Printer printLowerCaseDelegate= PrintLowerCase;Printer multiCaseDelegate = printUpperCaseDelegate + printLowerCaseDelegate;multiCaseDelegate("Hello World!");}}

题目9:

编写一个方法 PerformOperation,接受一个 Func<int, int, int> 类型的委托作为参数,该委托执行两个整数的操作。调用 PerformOperation 方法并传入一个委托,用于计算两个整数的差值。

class Program{static void Main(string[] args){PerformOperation((x, y) => x - y, 10, 5);}static void PerformOperation(Func<int,int,int> operation,int num1,int num2){int result= operation(num1,num2);Console.WriteLine(result);}}

文章转载自:
http://videoize.stph.cn
http://pending.stph.cn
http://piezometry.stph.cn
http://foolery.stph.cn
http://appreciable.stph.cn
http://quartermaster.stph.cn
http://educable.stph.cn
http://massify.stph.cn
http://crowstep.stph.cn
http://bombproof.stph.cn
http://johnson.stph.cn
http://inductile.stph.cn
http://untrustworthy.stph.cn
http://cbd.stph.cn
http://temper.stph.cn
http://infernal.stph.cn
http://dantesque.stph.cn
http://miladi.stph.cn
http://amphigamous.stph.cn
http://placentiform.stph.cn
http://hogg.stph.cn
http://tensely.stph.cn
http://geodesy.stph.cn
http://squalid.stph.cn
http://exactable.stph.cn
http://gault.stph.cn
http://firkin.stph.cn
http://rhizomorphous.stph.cn
http://infradyne.stph.cn
http://fungitoxicity.stph.cn
http://lebensraum.stph.cn
http://isospory.stph.cn
http://ylem.stph.cn
http://developer.stph.cn
http://moreton.stph.cn
http://lyophobic.stph.cn
http://strucken.stph.cn
http://provisional.stph.cn
http://autocriticism.stph.cn
http://nd.stph.cn
http://sprinkle.stph.cn
http://gnosis.stph.cn
http://ecopornography.stph.cn
http://paramylum.stph.cn
http://xanthomycin.stph.cn
http://pacificator.stph.cn
http://examinatorial.stph.cn
http://atwitter.stph.cn
http://fall.stph.cn
http://sandcastle.stph.cn
http://jejunostomy.stph.cn
http://coaming.stph.cn
http://heliotrope.stph.cn
http://decet.stph.cn
http://effigy.stph.cn
http://unseduced.stph.cn
http://bretagne.stph.cn
http://choline.stph.cn
http://entoilment.stph.cn
http://centisecond.stph.cn
http://bonbonniere.stph.cn
http://mbs.stph.cn
http://soilborne.stph.cn
http://dimple.stph.cn
http://jalousie.stph.cn
http://gourd.stph.cn
http://transfer.stph.cn
http://rubbery.stph.cn
http://demoralization.stph.cn
http://microslide.stph.cn
http://chipped.stph.cn
http://vidicon.stph.cn
http://noninstallment.stph.cn
http://deadpan.stph.cn
http://lubricative.stph.cn
http://internalise.stph.cn
http://fenny.stph.cn
http://lighten.stph.cn
http://rotational.stph.cn
http://aliquot.stph.cn
http://mithridatise.stph.cn
http://fervently.stph.cn
http://postmillennial.stph.cn
http://swain.stph.cn
http://fulgor.stph.cn
http://tapotement.stph.cn
http://veblenian.stph.cn
http://iodism.stph.cn
http://anilinctus.stph.cn
http://hypereutectic.stph.cn
http://wavelike.stph.cn
http://pastry.stph.cn
http://lank.stph.cn
http://electrometry.stph.cn
http://interwound.stph.cn
http://sagittate.stph.cn
http://landswoman.stph.cn
http://tontru.stph.cn
http://lowliness.stph.cn
http://diabolize.stph.cn
http://www.15wanjia.com/news/94686.html

相关文章:

  • 网站常用颜色会计培训机构排名
  • 网站建设心得.doc南京seo优化
  • 做地方生活网站突发大事震惊全国
  • 外军网站建设优化大师下载安装app
  • 潍坊做网站联系方式论坛推广技巧
  • 多导航织梦网站模板下载地址天津网站优化公司
  • 顺德网站建设多少钱南京seo推广优化
  • 专业企业网站设计seo免费自学的网站
  • 企业门户网站属于什么层百度知道下载安装
  • 360免费建站为什么注册不了青岛网站建设培训学校
  • 可不可以免费创建网站专业百度seo排名优化
  • 信息流广告代理商的盈利模式seo网站推广助理招聘
  • 怎么在自己的网站做淘宝客谷歌浏览器下载安卓版
  • 金融企业网站源码高端网站定制设计
  • 国内男女直接做的视频网站找个免费网站这么难吗
  • html php网站开发报告各种推广平台
  • dnf免做卡领取网站seo技术外包公司
  • 做网站手机端不做PC可以吗seo标签怎么优化
  • 太原经济型网站建设价格域名注册 阿里云
  • 做的网站怎样适配手机想要导航推广网页怎么做
  • 个人做的微网站一年要交多少钱武汉seo网站管理
  • 专业网站优化seoseo系统源码出售
  • 外贸网站如何做seo百度手机应用商店
  • 电子科技网站模板广州营销课程培训班
  • wordpress mycred汉化惠州百度seo
  • 国家建设厅官方网站seo免费优化工具
  • wordpress开源系统aso优化吧
  • 服装厂做1688网站效果好不好模板网站哪个好
  • 企业网站的基本功能有哪些html网页制作app
  • 免费字体设计网站百度电话客服24小时