请按照C#代码中的说明帮助我输出 [英] please help me with the output as instructed within the C# code
本文介绍了请按照C#代码中的说明帮助我输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于以下代码段,开发TODO评论所需的功能:
使用系统;
使用 System.Collections.Generic;
使用 System.Collections.ObjectModel;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
命名空间 ConsoleApplication1
{
class 计划
{
静态 void Main( string [] args)
{
ObservableCollection< MyItems> _list1 = new ObservableCollection< MyItems>();
_list1.Add( new MyItems( A001, 除臭剂, 10 跨度>));
_list1.Add( new MyItems( A0ZZ, 发胶, 20 跨度>));
_list1.Add( new MyItems( A002, 牙膏, 30 跨度>));
_list1.Add( new MyItems( 0001, Advacado, 0 跨度>));
ObservableCollection< MyItems> _list2 = new ObservableCollection< MyItems>();
_list2.Add( new MyItems( A001, 除臭剂, 10 跨度>));
_list2.Add( new MyItems( A002, 牙膏, 30 跨度>));
/ * TODO:开发逻辑,将添加_list1中尚未存在的所有项目进入_list2。应根据以下规则将项目添加到特定的
*索引位置:如果DisplaySequence不等于零,则根据
*插入到该值的正确位置;如果DisplaySequence等于零,则根据ItemName按字母顺序插入。以下foreach语句应按以下顺序输出
*:
*
* 0001 - Advacado
* A001 - 除臭剂
* A0ZZ - 发胶
* A002 - 牙膏
* /
foreach ( var i in _list2)
{
Console.WriteLine(i.ItemName + - + i.ItemDescription);
}
Console.WriteLine( 按任意键退出。< /跨度>);
Console.ReadKey();
}
}
class MyItems
{
public MyItems( string _itemName, string _itemDescription, int _displaySequence)
{
ItemName = _itemName;
ItemDescription = _itemDescription;
DisplaySequence = _displaySequence;
}
public string ItemName {获得跨度>; set ; }
public string ItemDescription { get 跨度>; set ; }
public int DisplaySequence { get 跨度>; set ; }
}
}
解决方案
想一想。这很简单。
ObservableCollection有几个方法 [ ^ ],如:添加
,插入
,包含
,IndexOf
。使用它们完成待办事项列表中列出的任务。 ;)
Given the following segment of code, develop the functionality desired at the TODO comment :
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ObservableCollection<MyItems> _list1 = new ObservableCollection<MyItems>();
_list1.Add(new MyItems("A001", "Deodorant", 10));
_list1.Add(new MyItems("A0ZZ", "Hairspray", 20));
_list1.Add(new MyItems("A002", "Toothpaste", 30));
_list1.Add(new MyItems("0001", "Advacado", 0));
ObservableCollection<MyItems> _list2 = new ObservableCollection<MyItems>();
_list2.Add(new MyItems("A001", "Deodorant", 10));
_list2.Add(new MyItems("A002", "Toothpaste", 30));
/* TODO: Develop logic that will add all items from _list1 that are not already present into _list2. Items should be added into specific
* index positions according to the following rule: if DisplaySequence is not equal to zero, insert into the correct position according
* to that value; if DisplaySequence is equal to zero insert alphabetically according to the ItemName. The below foreach statement should
* output in the following order:
*
* 0001 - Advacado
* A001 - Deodorant
* A0ZZ - Hairspray
* A002 - Toothpaste
*/
foreach (var i in _list2)
{
Console.WriteLine(i.ItemName + " - " + i.ItemDescription);
}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
class MyItems
{
public MyItems(string _itemName, string _itemDescription, int _displaySequence)
{
ItemName = _itemName;
ItemDescription = _itemDescription;
DisplaySequence = _displaySequence;
}
public string ItemName { get; set; }
public string ItemDescription { get; set; }
public int DisplaySequence { get; set; }
}
}
解决方案
Think of it. It's quite simple.
ObservableCollection has got several methods[^], like:Add
,Insert
,Contains
,IndexOf
. Use them to finish tasks listed on your ToDo list. ;)
这篇关于请按照C#代码中的说明帮助我输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文