0

How can i see the code inside of ForEach<T>(T[] array, Action<T> action)?

Not the definition only or how to use but the code inside of this method?

I just need to see how to change the parameter type when i put T as a type passed on that method.

Example:

Array.ForEach<string>(string[] array, Action<string> action);

Array.ForEach<int>(int[] array, Action<int> action);

Array.ForEach<whateverTypeHere>(whateverTypeHere[] array, Action<whateverTypeHere> action);

If i put any type inside <> the parameters also will change. How to do it anyway? :)

2
  • 7
    It's all about generics here. Commented Feb 15, 2012 at 9:08
  • I suggest you to read about generics, because like @ken2k said it's all about them! Basically the compiler creates a class for each generic type it finds in your code. Other than just out of curiosity, you should not need to know about the inner details of .net methods. Commented Feb 15, 2012 at 9:18

1 Answer 1

3
public class Test<TFirst,TSecond>
{
  public TFirst First;public TSecond Second;
}

if i create a new instance of this class, it will show like

Test<int,string> objName=new Test<int,string>{ First=1, Second="Microsoft"};

if you pass the type like int or string, automatically the compiler will infer the type of your property.

You have to try practicing it, then you will be able to understand

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.