Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int z = 1;
- double result = Math.Log(z); //works
- int[] z = new [] {1,2,3,4};
- double[] result = Math.Log(z); //Syntax 1 - error CS1503: Argument '1': cannot convert from 'int[]' to 'double'
- double[] result = z.Select(p => Log(p)).ToArray(); //Syntax 2 - OK
- static class LogExtension
- {
- public static IEnumerable<Double> Log(this IEnumerable<int> list)
- {
- foreach (int i in list)
- {
- yield return Math.Log(i);
- }
- }
- }
- IEnumerable<Double> logValues = myInts.AsEnumerable().Log();
- private static double[] getLogForIntArray(int[] z)
- {
- double[] q = (double[])z.Select(p => Math.Log(p)).ToArray();
- return q;
- }
- double[] q = getLogForIntArray(z); // Syntax 3
- int[] z = new [] {1,2,3,4};
- double[] result = Array.ConvertAll(z, p => Log(p));
- double Log(int i) { return Math.Log(i); }
- int[] z = new[] { 1, 2, 3, 4 };
- double[] result = Array.ConvertAll(z, Log);
- double[] x = Array.ConvertAll(z, p => Math.Log(p));
- int[] z = new [] {1,2,3,4};
- double[] result = z.Select(p => Log(p)).ToArray();
- IEnumerable<int> z = new[] {1, 2, 3, 4};
- IEnumerable<double> result = z.Select(i => Math.Log(i));
- var z = new[] {1, 2, 3, 4};
- var result = z.Select(i => Math.Log(i));
- for (int i = 0; i < z.Length; i++)
- {
- Math.Log(z[i]);
- }
- static void Process()
- {
- double[] test = { 1, 2, 3, 4 };
- double[] answer = new double[test.Length];
- for (int i = 0; i < test.Length; i++)
- {
- answer[i] = Math.Log(test[i]);
- }
- }
Add Comment
Please, Sign In to add comment