This challenge is related to the C# language. Note that challenges that require the answers to be in a specific language are generally discouraged.

learn more… | top users | synonyms

10
votes
4answers
547 views

reach catch when everything in the try block is caught already

This is limited to Java and C# by the syntax I guess. In this programming puzzle, you are to produce Exceptions that can be caught but are thrown again at the end of the catch block. try { ...
2
votes
9answers
1k views

Can you cancel the stackoverflow exception in the following code?

The following code will produce a run-time error, stackoverflow exception. class Foo { //static Foo foo = new Foo(); // you are not allowed using this approach //static readonly Foo foo = ...
12
votes
5answers
981 views

Code Injection works in C# too!

Given the following C# program outputting False, inject a 'malicious' line of code such that the program outputs True. class Program { static void Main() { ...
1
vote
2answers
229 views

Inherit from class with inaccessible abstract members and all constructors inaccessible

The class System.Globalization.EastAsianLunisolarCalendar of the mscorlib.dll assembly is non-nested public but its sole instance constructor is internal and it also declares some internal abstract ...
3
votes
1answer
477 views

Flip the commented-out code [closed]

This puzzle works for any programming language that has the same // single-line and /* ... */ multi-line comments that C++, C# and Java do. You are debugging an application. You find a fishy block of ...
15
votes
1answer
758 views

When is a giraffe not a giraffe?

I hope this kind of "riddle" is ontopic in Programming Puzzles & Code Golf. Give an example of a situation where the C# method below returns false: public class Giraffe : Animal { public bool ...
-6
votes
4answers
422 views

Write 'hello world' to standard output without using certain common words - C# only [duplicate]

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 ...
1
vote
1answer
515 views

Write the implementation to pass this test

Given the following test, implement an addOne function in C# so it passes, without any modification to the test. TIP: Yes, it is possible. [TestMethod] public void TheChallenge() { int a = 1; ...
0
votes
2answers
233 views

Storing a DNS name as compactly as possible in memory (preferably in C#) [closed]

What is the most compact way to encode/save DNS names in memory? For example, storing "www.google.com" as a string in .NET will result in the object being encoded as UTF-16, and it will consume twice ...
6
votes
9answers
2k views

Shortest Hello World program with no semi colons

I recently saw some questions on SO that asked if you could make a Hello World program without using any semi colons using C#. The challenge is to do this again, but in the shortest amount of code ...
15
votes
16answers
2k views

Tips for code-golfing in C#

What general tips do you have for golfing in C#? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C# (e.g. "remove comments" is not an ...