Skip to content

Instantly share code, notes, and snippets.

@siposm
Created February 19, 2026 06:49
Show Gist options
  • Select an option

  • Save siposm/399dc038f0b41ac1cf847497852fecf0 to your computer and use it in GitHub Desktop.

Select an option

Save siposm/399dc038f0b41ac1cf847497852fecf0 to your computer and use it in GitHub Desktop.
public class Tools
{
public int Add(int a, int b)
{
return a + b;
}
public void Log<T>(T param)
{
Console.WriteLine($"{param}");
}
public T FindMax<T>(T a, T b)
where T : IComparable
{
// if (a > b) // ?! nem értelmezhető --> megszorítás
return a.CompareTo(b) > 0 ? a : b;
}
public bool CompareByValue<T, K>(T valueA, K valueB)
{
return valueA.Equals(valueB);
}
public bool CompareByType<T, K>()
{
return typeof(T).Equals(typeof(K));
}
}
public class Box<T>
{
public T Value { get; set; }
public Box(T value)
{
this.Value = value;
}
public Box() { }
public override string ToString()
{
return $"Box({Value})";
}
}
public class CardboardBox<T, Z> : Box<string> { }
public class MisteryBox<T, Z> : Box<T>
{
// public MisteryBox(T value) : base(value)
// {
// }
}
public class Pair<K, V>
where K : IComparable
where V : class
{
public K Key { get; set; }
public V Value { get; set; }
public Pair(K key, V value)
{
this.Key = key;
this.Value = value;
}
}
public class ObjectFactory<T>
where T : new()
{
public List<T> Create(int number)
{
List<T> list = new List<T>();
for (int i = 0; i < number; i++)
{
list.Add(new T());
}
return list;
}
}
internal class Program
{
private static void Main(string[] args)
{
var tools = new Tools();
tools.Log("alma");
tools.Log(123);
tools.Log<string>("alma");
tools.Log<int>(123);
var box = new Box<string>("this is my box");
var pair = new Pair<int, Box<string>>(10, box);
var of = new ObjectFactory<Box<string>>();
var items = of.Create(4);
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment