What is a better practice, to combine two interfaces through extension, or to cast an interface to its implementing type
By : Fernando Ferreira
Date : March 29 2020, 07:55 AM
this one helps. There are two design forces at work: Keeping your interfaces as small as possible and minimizing the number of interfaces. In general, large interfaces are more problematic to refactor later. If your interfaces are already used throughout the system, you could split your client code into separate methods or classes, create an interface CreableHasDependencies that extends both interfaces, or just use the class type directly.
|
Why does using Delegate.Combine require a cast but using the + operator doesn't?
By : Eviltomato
Date : March 29 2020, 07:55 AM
hop of those help? I couldn't find the + operator in Reflector under Delegate or MulticastDelegate. , Taking the following example: code :
class Program
{
static void Main(string[] args)
{
Test1();
Test2();
}
public static void Test1()
{
Action a = () => Console.WriteLine("A");
Action b = () => Console.WriteLine("B");
Action c = a + b;
c();
}
public static void Test2()
{
Action a = () => Console.WriteLine("A");
Action b = () => Console.WriteLine("B");
Action c = (Action)MulticastDelegate.Combine(a, b);
c();
}
}
internal class Program
{
private static void Main(string[] args)
{
Program.Test1();
Program.Test2();
}
public static void Test1()
{
Action a = delegate
{
Console.WriteLine("A");
};
Action b = delegate
{
Console.WriteLine("B");
};
Action c = (Action)Delegate.Combine(a, b);
c();
}
public static void Test2()
{
Action a = delegate
{
Console.WriteLine("A");
};
Action b = delegate
{
Console.WriteLine("B");
};
Action c = (Action)Delegate.Combine(a, b);
c();
}
}
|
Cast<int>.Cast<int?> applied on generic enum collection results in invalid cast exception
By : Pedro Cabo Calvet
Date : March 29 2020, 07:55 AM
I wish this helpful for you Ok I have come to find out the cause, which is still strange. I should have checked up Cast implementation myself first of all! This is how Cast is implemented: code :
public static IEnumerable<TResult> Cast<TResult>(this IEnumerable source)
{
IEnumerable<TResult> enumerable = source as IEnumerable<TResult>;
if (enumerable != null)
{
return enumerable; // this is the culprit..
}
if (source == null)
{
throw Error.ArgumentNull("source");
}
return Enumerable.CastIterator<TResult>(source);
}
private static IEnumerable<TResult> CastIterator<TResult>(IEnumerable source)
{
foreach (object current in source)
{
yield return (TResult)((object)current);
}
yield break;
}
new[] { Gender.Male }.Cast<int>()
|
Operation to combine Where and Cast in LINQ
By : Carol J Elsip Wilson
Date : March 29 2020, 07:55 AM
this will help Actually you're looking for OfType<>(). Excerpt: code :
System.Collections.ArrayList fruits = new System.Collections.ArrayList(4);
fruits.Add("Mango");
fruits.Add("Orange");
fruits.Add("Apple");
fruits.Add(3.0);
fruits.Add("Banana");
// Apply OfType() to the ArrayList.
IEnumerable<string> query1 = fruits.OfType<string>();
Console.WriteLine("Elements of type 'string' are:");
foreach (string fruit in query1)
{
Console.WriteLine(fruit);
}
|
Validate that CAST date value is greater than another CAST date value not working
By : lostInTranslation
Date : March 29 2020, 07:55 AM
Any of those help You need to convert to date using the correct style (which in your case is style 101):
|