本文介绍了如何为Generic :: List< T>创建自定义Find方法在C ++ / CLI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发布此问题的答案,因为MSDN网络示例只列出了C#和VB,答案在C ++ / CLI有点不同。

I wanted to post an answer to this question because the MSDN Network Example only lists C# and VB and the answer is a bit different in C++/CLI.

答案是从这篇文章派生的:

This answer is derived from this post: Using "->Find" on a "List" in Visual C++

推荐答案

按照帖子链接的指导 ...

Following the guidance of the post link above...

首先我创建了一个类作为我的Predicate委托:

First I created a class to use as my Predicate delegate:

public value class FindComponentView
{
  String^ Value;

public:

  FindComponentView(String^ value)
  {
    Value = value;
  }
  bool IsMatch(ComponentDrawingData^ compDD)
  {
    return compDD->Identifier->Value == Value;
  }
};

然后我可以像下面这样实现Find()方法:

I was then able to implement the Find() method like this:

// Note: ComponentDrawingDataList^ derives from System::Collections::Generic::List<T>^

ComponentDrawingDataList^ ddList = GetComponentDrawingDatas(component);
ComponentDrawingData^ componentDrawingData = 
  ddList->Find(gcnew System::Predicate<ComponentDrawingData^>(gcnew FindComponentView("View_1"), &FindComponentView::IsMatch));

这篇关于如何为Generic :: List&lt; T&gt;创建自定义Find方法在C ++ / CLI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 23:18