Last active
December 12, 2020 13:33
-
-
Save zengjiapei3000/13f93641778408d3689609e5f24fd1b4 to your computer and use it in GitHub Desktop.
In csharp, how to convert intArray to chararray, and the difference of csharp 2 and 3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConvertIntarrayToChararray | |
{ | |
public int FindMaxConsecutiveOnes(int[] nums) { | |
char[] numsToChars = new char[nums.Length]; | |
numsToChars = nums.ConvertAll<int, char>(nums, c => char.Parse(c)); // C# 3.0 | |
// In C# 2.0, replaced the above code to : | |
// numsToChars.ConvertAll<int, char>(nums, delegate(int c) { return char.Parse(c)}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe it's wrong, because I don't think about covariance and contravariance in generics. 😳