using System;using System.Collections.Generic;using System.Text;namespace ConsoleApplication3Generics{ class Program { static voID Main(string[] args) { ScheduleSelectedItems sitems = new ScheduleSelectedItems("Yusuf"); ScheduleSelectedItemsList sList = new ScheduleSelectedItemsList(); sList.Items.Add(sitems); Console.Write(sList.Items[0].ToString()); Console.ReadKey(); } } public class ScheduleSelectedItems { private string Ad; public ScheduleSelectedItems(string ad) { Ad = ad; } } public class ScheduleSelectedItemsList { public List Items; public ScheduleSelectedItemsList() { Items = new List(); } }}
如何在我的控制台上添加“yusuf”?
解决方法public class ScheduleSelectedItems { private string Ad; public ScheduleSelectedItems(string ad) { Ad = ad; } public overrIDe string ToString() { return this.Ad; } }总结
以上是内存溢出为你收集整理的c# – ToString()不返回预期的字符串全部内容,希望文章能够帮你解决c# – ToString()不返回预期的字符串所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)