I have several controls that all inherit from UserControl, and I have a method MergeSortthat works in types UserControl(so that I cannot write 6 different methods), but when I return to my usual controls after sorting, it raises an error that am i doing wrong? The mergesort method requires a property Leftthat every user control uses, so how can I do this?
UserControl
MergeSort
Left
The MergeSort method looks like this:
public UserControl[] MergeSort(UserControl[] array)
Casting is as follows:
(CustomControl[])MergeSort(customControlArray);
I think you need to drop each one manually:
CustomControl[] customControlArray; ... UserControl[] sortedControls = MergeSort(customControlArray); CustomControl[] sortedCustomControls = Array.ConvertAll<UserControl, CustomControl>(sortedControls, delegate(UserControl control) { return (CustomControl)control; });
.NET 3.5+ , "cooler".:)
: :
UserControl[] sortedControls = customControlArray.ToList().ConvertAll(c => (CustomControl)c).ToArray();
: -)
( , , .)
, UserControl, . , , , , , ..
MyCustomControl
ICustomControl
. , , - , . ( ) ( ). , , :)
Source: https://habr.com/ru/post/1795061/More articles:CakePHP-based website becomes outdated in browser - cakephpNSURLConnection NSMutableURLRequest and HTTPS - httpsHow to send automatic email to daily, weekly and monthly databases? - c #ะะพัะตะผั ัะฐะทะฝะธัะฐ ะฒ UIAlertView? - cReactive Extensions User Interface Update - silverlight3.5 VS 4.0.NET Framework - c #How to sign my test suite with a system key? - androidThe problem of using generics in a function - javaCGI, python and setgid - pythonHow to create a file on the server? - phpAll Articles