public static IList <T> BubbleSort <T>(this IList <T> list, PredicateDelegate <T> predicate) { int i = list.Count - 1; while (i > 0) { int swap = 0; for (int j = 0; j < i; j++) { if (predicate(list[j], list[j + 1])) { var temp = list[j]; list[j] = list[j + 1]; list[j + 1] = temp; swap = j; } } i = swap; } var newList = new List <T>(); for (int index = 0; index < list.Count; index++) { newList.Add(list[index]); } return(newList); }
static void Main(string[] args) { VoidDelegate <int> var1 = Void2; VoidDelegate <double> var2 = Void3; VoidDelegate <string> var3 = Void4; VoidDelegate <int, double, string> var6 = Void6; VoidDelegate <string, double, int> var7 = Void7; VoidDelegate <int, int, int> var8 = Void8; ReturnDelegate <int, int> var9 = Return2; ReturnDelegate <double, string> var10 = Return3; ReturnDelegate <string, double> var11 = Return4; ReturnDelegate <int, double, string, char> var12 = Return6; ReturnDelegate <string, double, int, long> var13 = Return7; ReturnDelegate <int, int, int, byte> var14 = Return8; PredicateDelegate <int> var15 = BoolMethod1; PredicateDelegate <string> var16 = BoolMethod2; PredicateDelegate <double> var17 = BoolMethod3; PredicateDelegate <byte> var18 = BoolMethod4; }
public RelayCommand(Action execute, PredicateDelegate canExecute) { if (execute == null) throw new ArgumentNullException("execute"); _execute = execute; _canExecute = (object obj) => { return canExecute(); }; }
public static void Start() { var nums = new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; //Now that we're using a generic delegate type we'll have to specify that we're passing it an int... PredicateDelegate <int> predicateDelegate = Predicate; var result = Filter(nums, Predicate); }
public static List<int> FilterRecords(this List<int> OldList, PredicateDelegate FilterFunction) { var result = new List<int>(); foreach (var item in OldList) { if (FilterFunction(item) == true) result.Add(item); } return result; }
public static void Example1() { var nums = new List<int> { 12, 10, 13, 09, 11, 19, 11, 08, 16, 10, 12, 10, 05, 09, 11, 14 }; var delTen = new PredicateDelegate(PredicateMethods.IsGreaterThan10); foreach (var element in nums.FilterRecords(delTen)) { Console.WriteLine(element.ToString()); } }
static void Main(string[] args) { Console.WriteLine("*LastDigitComparer + BubbleSort: "); Console.WriteLine(); var array = new List <int>() { 2, 4, 1, 6, 10 }; var sortedArray = array.BubleSort(new LastDigitComparer()); foreach (var item in sortedArray) { Console.WriteLine(item); } Console.WriteLine(); Console.WriteLine("BubbleSort with Delegate - Predicate for Compare Integers : "); Console.WriteLine(); var secondArrey = new List <int>() { 2, 4, 1, 6, 10 }; PredicateDelegate <int> myDelegate = CompareIntegers; var sortedArreyPredicate = secondArrey.BubleSort(myDelegate); foreach (var item in sortedArreyPredicate) { Console.WriteLine(item); } Console.WriteLine(); Console.WriteLine("*ReverseComparer<T> + StringLengthComparer + SelectionSort: "); Console.WriteLine(); var strings = new List <string>() { "grr", "brrr", null, "aaaaa", "yeaaaaa", "A" }; var stringsArray = strings.SelectionSort(new ReverseComparer <string>(new StringLengthComparer())); strings.Add("o"); foreach (var item in stringsArray) { if (item == null) { Console.WriteLine("\"null\""); } else { Console.WriteLine(item); } } Console.WriteLine(); }
/// <summary> /// Using annonymous methods and Lambda expressions /// We are assigning Delegate instance delTen with a Lambda method /// </summary> public static void Example2() { var nums = new List<int> { 12, 10, 13, 09, 11, 19, 11, 08, 16, 10, 12, 10, 05, 09, 11, 14 }; var delTen = new PredicateDelegate(x=>x>15? true:false); foreach (var element in nums.FilterRecords(delTen)) { Console.WriteLine(element.ToString()); } }
static IEnumerable Filter(IEnumerable src, PredicateDelegate pred) { foreach (object item in src) { if (pred(item)) { yield return(item); } } }
internal Predicate(LibraryMethodList container, Functor functor, PredicateDelegate predicateDelegate, bool canEvaluate) : base(container, functor, canEvaluate) { if (predicateDelegate == null) { throw new ArgumentNullException("predicateDelegate"); } m_predicateDelegate = predicateDelegate; }
public void Print(PredicateDelegate predicate) { foreach (var t in _table) { Console.ForegroundColor = predicate(t) ? ConsoleColor.Green : ConsoleColor.White; Console.Write(t + " "); } Console.WriteLine(); Console.WriteLine(); }
static IEnumerable Filter(IEnumerable stds, PredicateDelegate pred) { foreach (object o in stds) { if (pred(o)) { yield return(o); } } }
public IEnumerable <T> FindDelegate(PredicateDelegate <T> predicado) { foreach (var item in _items) { if (item != null && predicado(item)) { yield return(item); } } }
public RelayCommand(Action execute, PredicateDelegate canExecute) { if (execute == null) { throw new ArgumentNullException("execute"); } _execute = execute; _canExecute = (object obj) => { return(canExecute()); }; }
// PredicateDelegate is passed IItemDataTyped objects public IAsyncOperation <IList <ItemKey> > SelectKeysAsync(PredicateDelegate predicate) { if (predicate == null) { throw new ArgumentNullException("predicate"); } return(AsyncInfo.Run(async cancelToken => { return await this.SelectKeysAsync(predicate, cancelToken); })); }
private void BuscarPares(Lista <int> lista) { //Delegado anónimo PredicateDelegate <int> paresDelegate = delegate(int i) { return(i % 2 == 0); }; var listaPares = lista.FindDelegate(paresDelegate); Console.WriteLine("Pares:"); foreach (var item in listaPares) { Console.WriteLine("- " + item.ToString()); } }
//We're not really doing anything integer specific - just creating a list, looping through it, passing each int into our //generic predicate delegate, and adding and returning the results. We can remove the references to int and make this method //generic as well. Can't really call it filter integers any more, since we can filter way more than ints... public static IEnumerable <T1> Filter <T1>(IEnumerable <T1> list, PredicateDelegate <T1> predicateDelegate) { var result = new List <T1>(); foreach (T1 i in list) { if (predicateDelegate(i)) { result.Add(i); } } return(result); }
// PredicateDelegate is passed IItemDataTyped objects public IAsyncOperation <IList <IItemDataTyped> > SelectAsync(PredicateDelegate predicate) { if (predicate == null) { throw new ArgumentNullException("predicate"); } return(AsyncInfo.Run(async cancelToken => { using (await CrossThreadLockScope.Enter(m_lock)) { return await m_items.SelectAsync(predicate, cancelToken); } })); }
public static IEnumerable <int> FilterIntegers(IEnumerable <int> list, PredicateDelegate predicateDelegate) { var result = new List <int>(); foreach (int i in list) { if (predicateDelegate(i)) { result.Add(i); } } return(result); }
static IEnumerable Filter(IEnumerable stds, PredicateDelegate pred) { IList res = new ArrayList(); foreach (object o in stds) { if (pred(o)) { res.Add(o); } } return(res); }
internal Predicate Add(Functor functor, PredicateDelegate predicateDelegate, bool canEvaluate) { if (functor == null) { throw new ArgumentNullException("functor"); } if (predicateDelegate == null) { throw new ArgumentNullException("predicateDelegate"); } var predicate = Methods.Add(functor, predicateDelegate, canEvaluate); return(predicate); }
static IEnumerable <int> FilterIntegers(IEnumerable <int> items , PredicateDelegate predicate) { var ret = new List <int>(); foreach (var item in items) { if (predicate(item)) { ret.Add(item); } } return(ret); }
static IEnumerable Filter(IEnumerable src, PredicateDelegate pred) { IList res = new ArrayList(); foreach (object item in src) { // if(pred.Invoke(item)) if (pred(item)) { res.Add(item); } } return(res); }
/// <summary> /// 让外界指定数据筛选的方法 /// </summary> /// <param name="list"></param> /// <param name="predicate"></param> /// <returns></returns> static IEnumerable <int> FilterIntegers(IEnumerable <int> list, PredicateDelegate predicate) { //找出所有的偶数,放到List<int>集合中 var result = new List <int>(); foreach (var num in list) { if (predicate(num)) { result.Add(num); } } return(result); }
//public static List<TOut> Select<TIn, TOut>(this TIn[] input, SelectDelegate<TIn, TOut> select) => // input.ToList().Select(select); public static List <T> Where <T>(this IEnumerable <T> enumerable, PredicateDelegate <T> predicate) { var list = new List <T>(); foreach (var thing in enumerable) { var wrap = new ReferenceWrapper <bool>(false); predicate(thing, wrap); if (wrap) { list.Add(thing); } } return(list); }
internal async Task <IList <ItemKey> > SelectKeysAsync(PredicateDelegate predicate, CancellationToken cancelToken) { if (predicate == null) { throw new ArgumentNullException("predicate"); } List <ItemKey> matches = new List <ItemKey>(); for (int i = 0, max = this.KeyCount; i < max; ++i) { IItemDataTyped item = await this.GetItemAsync(i, true, cancelToken); if (item != null && predicate(item)) { matches.Add(item.Key); } } return(matches); }
static void Main(string[] args) { PredicateDelegate.IfValid(); ActionDelegate.Save(); FuncDelegate.MainFunc(); DelegatesFunc(); FuncActionPred.PredicateDemo(); FuncActionPred.ActionDemo(); FuncActionPred.FuncDemo(); //multi cast delegates MultiCastDelegates.DelFunc(); //using lambda DelegateEx1.UsingLambda(); //without lambda DelegateEx1.AddData(); }
public static bool Any <T>(this List <T> enumerable, PredicateDelegate <T> predicate = null) { if (predicate == null) { return(enumerable.Count > 0); } Kernel.PrintDebug("Hi from any"); var wrap = new ReferenceWrapper <bool>(false); Kernel.PrintDebug("ref yes"); foreach (var thing in enumerable) { Kernel.PrintDebug("foreach ok"); predicate(thing, wrap); Kernel.PrintDebug("predicate ok"); if (wrap) { return(true); } } return(false); }
internal Predicate Add(Functor functor, PredicateDelegate predicateDelegate, bool canEvaluate) { if (functor == null) { throw new ArgumentNullException("functor"); } if (predicateDelegate == null) { throw new ArgumentNullException("predicateDelegate"); } if (Contains(functor)) { throw new ArgumentException("Item already exists.", "functor"); } var predicate = new Predicate(this, functor, predicateDelegate, canEvaluate); Items.Add(predicate); Library.Touch(); return(predicate); }
// PredicateDelegate is passed IItemDataTyped objects public IAsyncOperation<IList<ItemKey>> SelectKeysAsync(PredicateDelegate predicate) { if (predicate == null) { throw new ArgumentNullException("predicate"); } return AsyncInfo.Run<IList<ItemKey>>(async cancelToken => { using (await CrossThreadLockScope.Enter(m_lock)) { return await m_items.SelectKeysAsync(predicate, cancelToken); } }); }
internal async Task<IList<ItemKey>> SelectKeysAsync(PredicateDelegate predicate, CancellationToken cancelToken) { if (predicate == null) { throw new ArgumentNullException("predicate"); } List<ItemKey> matches = new List<ItemKey>(); for (int i = 0, max = this.KeyCount; i < max; ++i) { IItemDataTyped item = await this.GetItemAsync(i, true, cancelToken); if (item != null && predicate(item)) { matches.Add(item.Key); } } return matches; }
public MarkableInvocationGraph(PredicateDelegate predicate) { this.predicate = predicate; }
internal Predicate Add(Functor functor, PredicateDelegate predicateDelegate, bool canEvaluate) { if (functor == null) { throw new ArgumentNullException("functor"); } if (predicateDelegate == null) { throw new ArgumentNullException("predicateDelegate"); } Predicate predicate = Methods.Add(functor, predicateDelegate, canEvaluate); return predicate; }
internal void Add(string name, string op, int arity, PredicateDelegate predicateDelegate, bool canEvaluate) { Add(new Functor(name, arity), predicateDelegate, canEvaluate); Add(new Functor(op, arity), predicateDelegate, canEvaluate); }
public FilterEnumerator(IEnumerator enumerator, PredicateDelegate pred) { this.src = enumerator; this.pred = pred; }
public FilterEnumerable(IEnumerable src, PredicateDelegate pred) { this.src = src; this.pred = pred; }
public DelegateCondition(PredicateDelegate predicate) { Predicate = predicate; }
// PredicateDelegate is passed IItemDataTyped objects public IAsyncOperation<IList<ItemKey>> SelectKeysAsync(PredicateDelegate predicate) { if (predicate == null) { throw new ArgumentNullException("predicate"); } return AsyncInfo.Run(async cancelToken => { return await this.SelectKeysAsync(predicate, cancelToken); }); }