Skip to content

Instantly share code, notes, and snippets.

@zengjiapei3000
Last active December 12, 2020 13:33
Show Gist options
  • Save zengjiapei3000/13f93641778408d3689609e5f24fd1b4 to your computer and use it in GitHub Desktop.
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.
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)});
}
}
@zengjiapei3000
Copy link
Author

Maybe it's wrong, because I don't think about covariance and contravariance in generics. 😳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment