Skip to content

Instantly share code, notes, and snippets.

@renestein
Created April 11, 2013 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renestein/5361349 to your computer and use it in GitHub Desktop.
Save renestein/5361349 to your computer and use it in GitHub Desktop.
//https://twitter.com/mormegil_cz/status/321991296019484672
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Mormegill_test
{
internal class Program
{
private static void Main(string[] args)
{
var program = new Program();
Object[] devilArray1 =
{
generateInnerArray<Program>()
};
Object[] devilArray2 =
{
generateInnerArray<String>()
};
Console.WriteLine(program.Test(devilArray1));
Console.WriteLine(program.Test(devilArray2));
Console.ReadLine();
}
private static T[] generateInnerArray<T>()
{
return new T[] {default(T)};
}
private bool Test<T>(T[] arr)
{
return arr.Any(x => x is T[]);
}
}
}
@mormegil-cz
Copy link

Tak teď už si nerozumíme asi vůbec. :) V tomhle případě je T pořád object (zkuste si v Test vypsat typeof(T)…). Šlo mi o typ toho vrchního pole (tedy čím jiným ještě může být kromě Object[]). Nebo formulováno ještě jinak: Co všechno dokážete dostat za výstup z téhle metody?

void Test<T>(T[] arr)
{
    if (arr.Any(x => x is T[])) Console.WriteLine(typeof(T).FullName);
}

@renestein
Copy link
Author

Já vím, že T je pořád Object. Myslel jsem si po té vaší první odpovědi, že jste jen špatně formuloval, o co usilujete. :)

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