IEnumerable的<字节>结果返回另一个方法 [英] IEnumerable<byte> result return to another method
问题描述
你好
我对IEnumerable有点失落。通常我会使用List< byte>但在我们的编程过程中,Resharper建议使用IEnumerable< byte>。但只想检查这是否正确实施?我们如何初始化它?
I'm a bit lost with the IEnumerable. Normally I would have use a List<byte> but during our programming Resharper suggesting making use of IEnumerable<byte>. But just want to check if this is correct implementation? And how do we initialize it?
public IEnumerable<byte> BuildRecipeSendMessage(int DataIndex, DataTable RawRecipeData)
{
int recipeType = ModbusRecipeRawData.RecipeTypeID;
IEnumerable<byte> messageArray = new List<byte>();
switch (recipeType)
{
case 1:
var recipeTypeSite = new RecipeTypeSite();
recipeTypeSite.RecipeID = Convert.ToInt16(RawRecipeData.Rows[DataIndex][0]);
recipeTypeSite.IDDescription = RawRecipeData.Rows[DataIndex][1].ToString();
messageArray = _recipeMessageDefinition.BuildSiteMessageData(DataIndex, recipeTypeSite);
break;
case 2:
var recipeTypePlant = new RecipeTypePlant();
recipeTypePlant.RecipeID = Convert.ToInt16(RawRecipeData.Rows[DataIndex][0]);
recipeTypePlant.IDDescription = RawRecipeData.Rows[DataIndex][1].ToString();
messageArray = _recipeMessageDefinition.BuildPlantMessageData(DataIndex, recipeTypePlant);
break;
case 3:
var recipeTypeLocation = new RecipeTypeLocation();
recipeTypeLocation.RecipeID = Convert.ToInt16(RawRecipeData.Rows[DataIndex][0]);
recipeTypeLocation.IDDescription = RawRecipeData.Rows[DataIndex][1].ToString();
messageArray = _recipeMessageDefinition.BuildLocationMessageData(DataIndex, recipeTypeLocation);
break;
case 4:
var recipeTypeProduct = new RecipeTypeProducts();
recipeTypeProduct.RecipeID = Convert.ToInt16(RawRecipeData.Rows[DataIndex][0]);
recipeTypeProduct.IDDescription = RawRecipeData.Rows[DataIndex][1].ToString();
messageArray = _recipeMessageDefinition.BuildProductMessageData(DataIndex, recipeTypeProduct);
break;
}
return messageArray;
}
labjac
推荐答案
您好labjac,
Hi labjac,
>>但只想检查这是否正确实施?我们如何初始化它?
>> But just want to check if this is correct implementation? And how do we initialize it?
是的,这是一个正确的实现。
Yes, this is a correct implementation.
列表<>实现接口IEnumerable<>,所以你可以分配如下:
The List<> implements the interface IEnumerable<>, so you can assign as follows:
IEnumerable<byte> messageArray = new List<byte>();
顺便提一下,我注意到你还创建了以下线程:
Various classes or rather various methods inside a Class
String Padleft但需要0x00而不是十六进制30
如果这些线程中的问题已解决,请发布" ;标记为答案"如果他们面临类似的问题,它将帮助其他
If the issues in these threads are solved, please post "Mark as answer" to the appropriate answer , so that it will help other
成员快速找到解决方案。
members to find solution quickly if they faces similar issue.
这篇关于IEnumerable的<字节>结果返回另一个方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!