-9
\$\begingroup\$

This question already has an answer here:

The challenge is to write the string hello world to your processes standard output, using as few characters of code as possible.

The following restrictions apply:

  • The following words may not appear anywhere in the code in any casing (this includes as part of another word)

    1. Console
    2. Debug
    3. Write
    4. Print
    5. Line
    6. Put
  • Your code must compile as C# 4/4.5

  • No external libraries are permitted.

  • Your process may not spawn any new processes.

A working (but not necessarily the shortest) solution will be provided after a number of answers have been provided.

The winner is the author of the shortest code by character count that satisfies the above criteria.

\$\endgroup\$

marked as duplicate by Johannes Kuhn, Kevin Brown, flornquake, beary605, grc Jun 17 '13 at 10:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ There is at least one solution to this in the answers to codegolf.stackexchange.com/questions/5550/… \$\endgroup\$ – Peter Taylor May 14 '13 at 15:50
  • \$\begingroup\$ @PeterTaylor - none of the C# answers posted for that challenge satisfy the word usage restriction. \$\endgroup\$ – PhonicUK May 14 '13 at 16:29
  • \$\begingroup\$ w0lf's one does. There are also some answers in codegolf.stackexchange.com/questions/307/obfuscated-hello-world which demonstrate a technique which could be applied to the trivial hello world program (and which I see Johannes Kuhn has used in his answer). \$\endgroup\$ – Peter Taylor May 14 '13 at 17:57
  • \$\begingroup\$ @JohannesKuhn how is it a duplicate? The restrictions are completely different. \$\endgroup\$ – PhonicUK May 14 '13 at 19:19
  • \$\begingroup\$ Not exactly. You may violate 1 rule of the other question, and for C# it have to be rule 1 (class is needed). All of the words you list here except put violate rule 2. That means the difference is that on the other question put and other languages are allowed and here the characters eor0127 are allowed. Not very big. \$\endgroup\$ – Johannes Kuhn May 14 '13 at 19:48
3
\$\begingroup\$

75 chars

New answer, new approach.

class M{static void Main(){System.\u0043onsole.\u0057rite("hello world");}}

It looks like you can hide every character with a \uXXXX sequence. Which makes this thing...
Easy.

\$\endgroup\$
0
\$\begingroup\$

Ok, I try my luck:

118 chars

class M{static void Main(){System.Type.GetType("System.\x43onsole").GetMethods()[78].Invoke(0,new[]{"hello world"});}}

Based on this solution.

Idone

As noted in the original answer, the index of the Write method might be different on your system.

\$\endgroup\$
  • \$\begingroup\$ 'Object of type 'System.String' cannot be converted to type 'System.Int32'' You were right about the index not being the same. Since it doesn't run for me I can't accept this particular answer. \$\endgroup\$ – PhonicUK May 14 '13 at 18:21
  • \$\begingroup\$ It runs on Idone. You have to change the index. Try 78. \$\endgroup\$ – Johannes Kuhn May 14 '13 at 18:50
0
\$\begingroup\$

Here's my current best that runs anywhere:

158 Characters

using System;class M{static void Main(){Type.GetType("System.\x43onsole").GetMethod("\x57rite\x4cine",new[]{typeof(string)}).Invoke(0,new[]{"hello world"});}}

.Invoke ignores the first param entirely if its a static method, so you can use 0 instead of null to save 3 characters.

Additionally, a variation that bans the use of the \ character:

234 Characters

using System;using System.Linq;class M{static void Main(){Func<string,string>f=(i)=>new string(i.Reverse().ToArray());Type.GetType(f("elosnoC.metsyS")).GetMethod(f("eniLetirW"),new[]{typeof(string)}).Invoke(0,new[]{"hello world"});}}
\$\endgroup\$
0
\$\begingroup\$

183 chars

Without reflection "cheats"! (but using the deprecated overload of FileStream to avoid using SafeFilePointer)

using System;using System.IO;public class M{static void Main(){new MemoryStream(Convert.FromBase64String("SGVsbG8gV29ybGQ=")).CopyTo(new FileStream(new IntPtr(-11),(FileAccess)2));}}
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.