7

Is it possible to invoke a common method in a list without iteration?

 3 years ago
source link: https://www.codesd.com/item/is-it-possible-to-invoke-a-common-method-in-a-list-without-iteration.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Is it possible to invoke a common method in a list without iteration?

advertisements

I'm using C# and I don't know if it's possible invoke a method for all the object in a list in the same moment, without loop like for or foreach.

class Person
{
    public void doSomething()
    {
    //
    }
}

List<Person> _personlist = new List<Person>();

_personlist(SelectAll.doSomething()); //something like this
//invoke the same method at the same time for all the object in the list

I think that Linq allow this, but at the moment I don't find anything.


If you want to write a query that can operate in parallel check out plinq.

var _personlist = new List<Person>();
_personlist.AsParallel().ForAll(i=>i.DoSomething());

Tags linq

Related Articles

Access the common methods of each object by iterating through a list

I have multiple types of object instances that inherit from a common interface. I would like to access the common methods from each objects by iterating through a list or arraylist or collections. how do I do that? { interface ICommon { string getNam

Is it possible to load the object with all lazy properties without iteration?

I have an object which has children, some of which loaded lazy some not. Now I have situation where I need a parent object to load with all the child at once. Is there quick way to do this without checking Hibernate.isInitialized() on all the propert

Is it possible to invoke an export & ldquo; private & rdquo; method in c ++

Is it possible to invoke a private method of a class exported from a DLL? Will it be hidden from people who would like to use it but are not supposed to? thanks :)Yes, it's possible, but you need to use dirty casting tricks or rely on semi-undefined

Is there a way to invoke a static method of a class using a string that has the name of the class?

I have an array of strings containing names of classes. Is it possible to invoke the static methods of the actual class using the 'name of the class' in the string array. public class SortCompare { // There are classes called 'Insertion', 'Selection'

Invoking a custom method when receiving an exception in a test

I am looking to find is it possible to invoke a custom method whenever an exception is thrown in a test. i.e I have several tests (annotated @Test) and I want to write only one method that handles the exceptions in my way (for example writing custom

How do I run a static method on a CFC without using cfinvoke?

How do I invoke a static method on a CFC without using cfinvoke? I know that I can do this: <cfinvoke component="MyComponent" method="myStaticMethod' arg1="blah" returnvariable=myReturnVar> I would like to be able to invoke

Rails common method for updating a database field

I am new to rails and I have a task to write a common method that will update a specific database field with a given value. And I should be able to invoke the method from anywhere in the app.(I understand about the security flaw and so on.. But I was

Is it possible to replace a static method in a derived class?

I have a static method defined in a base class, I want to override this method in its child class, is it possible? I tried this but it did not work as I expected. When I created an instance of class B and invoke its callMe() method, the static foo()

Use Reflection to invoke a public method

I'm writing an API and I ran into an issue with using reflection. What I want to do is call a method from a custom object class and return the value to the spot called. The start of the call occurs in the MainActivity.java public class MainActivity e

Why can not I invoke non-static methods as an argument in the constructor?

This question already has an answer here: Why can't I refer to an instance method while explicitly invoking a constructor? 6 answers valid code 1: class ClassForTest{ ClassForTest(int k){ }; ClassForTest(){ this(2); method(); }; int method(){return 1

SuperClass Common Method Implementation

I'm fairly new to OO programming specifically with Java. I have a question pertaining to inheritance. I have a printing method that I'd like to be common among subclasses. The code in the print method is usable for all subclasses except for a respons

AngularJS: Triggering an event to invoke a service method inside a controller method

In code below I've created a module with a service and a controller. The service contains a single method which I am sharing and invoking within the controller. This code below represents a working implementation: !(function() { 'use strict'; var app

Dynamically instantiate classes that implement an interface and invoke an interface method

I have an interface, LogParser, consisting of a single method parse(String x). I also have an ArrayList containing the names of multiple classes which all implement LogParser. Is it possible to loop through this list of class names and dynamically in

have exceptional management as common method in ruby

Can someone tell me is there a way to make the exception handling as a common method and use it inside a methods, Let me explain it further, Ex: I have following methods def add(num1, num2) begin num1 + num2 rescue Exception => e raise e end end def

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK