9
May
C# obsesión – how many characters you are able to put into type? :)
I was writing some return type from function when I got brilliant dumb idea to start playing with braces, question marks etc.
And I came with some self-competition to write a lot of different characters into a valid type definition (in C#, of course). And simple repeating doesn’t count. But why not to create this as a public competition.
With the short first try I ended up with this:
IEnumerable<KeyValuePair<int, int?>?[,]>
That’s probably not the best what can be done. Do you have better idea? OK, it’s your turn. Use comments. The best – I’m the referee – will get the lolipop.
Sorry for all spanish speaking people if the word in title isn’t right.



There's 13 Comments So Far
May 11th, 2009 at 00:39
Hi, here is my type. Without namespaces, it looks like this:Func>,Expression>,Expression >>It’s not something I made up right now. I’ve been actually using this here: http://tomasp.net/blog/dynamic-linq-queries.aspx However, you get some bonus points for using funky symbols like “?”, “[,]“.Did I win some prize
? T.
May 11th, 2009 at 09:12
Hi Tomas,nice, but I’m afraid, this is simple repeating. :\ But you’re right now on 2nd place and that’s half of lolipop.
Let’s see what will others create.
May 11th, 2009 at 11:35
You write about C# obsession and you forget to use this most significant character
) IEnumerable?[,]>#if DEBUG []#endif myMember;
May 11th, 2009 at 11:42
What character do you mean? The ‘#’? I have doubts it’s allowed in type definiton.
May 11th, 2009 at 11:55
# of course. Just try what I created… It works fine. I wouldn’t suggest anyone to use such things, but the same is true for your type definition, isn’t it?
May 11th, 2009 at 12:34
Yes. But the ‘#’ isn’t valid for type (at least I think). I’m interested only in pure type definition characters.
May 11th, 2009 at 13:14
Using #if in type definition is definitely valid.The rest is question of interpretation. If you look on given compilation result then type definition is unconditional (it doesn’t contains #). But if you look on C# source then definition of type is conditional and contains # character.According to rules you presented in this blog I assume that source definition is important.
May 11th, 2009 at 13:23
The #if isn’t defining the type nor it’s part of type. It’s conditional directive, for compiler. It’s valid code, but not type (only type).
<joking>And I’ll be choosing the winner, hence I say no.
</joking>
May 11th, 2009 at 17:04
I don’t agree
But it’s certainly wise choice from you, because at the moment you allow it, someone can suggest someting like#if (DEBUG && !VC_V7)So what about this:IEnumerable<KeyValuePair<global::System.Int32, int?>?[,]>There is . and :
May 11th, 2009 at 17:12
Yep, somebody can suggest this, but for me it’s not a type definition (in my definition).
The ‘:’ and ‘.’ it’s good, extra points added.
May 11th, 2009 at 17:41
One extra character:
@IEnumerable<KeyValuePair<global::System.Int32, int?>?[,]>
May 11th, 2009 at 21:49
Nice. I didn’t even know that the ‘@’ is working here.
June 26th, 2009 at 19:09
There were good improvements to my base, but only one can be winner – the idea with “@” from pbouda. I’ll try to contact you via email and find some way to give you the prize (lolipop or beer).
Share your thoughts, leave a comment!