Cast Derived Type parameter object to base

CSharp · Console

/Program.cs

using System;

public class Program
{
	public static void Main()
	{
		Segment<Key> test = new Segment<Key>();
		var test2 = test as ISegment<SomeStructure>;
		Console.WriteLine("Hello World");
	}
}

public interface ISegment<out T>
{
}

public class SomeStructure
{
}

public class Key : SomeStructure
{
}

public class Segment<K> : ISegment<K> where K : SomeStructure
{
}
;