Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [c#]

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

0
votes
0answers
96 views

C# puzzle - execute impossible code [duplicate]

This is a small challenge which was given in my workplace, ...
5
votes
1answer
322 views

Help golfing this solution further

We are doing a PCG challenge at work, and I'm submitting answers in C#. This is a modification of the "M'Kay" challenge. My solution has been deemed correct by the requirements, I'm just trying to ...
1
vote
0answers
331 views

Write a semi-compact FizzBuzz that can scale handle to “unlimited” if cases [closed]

I saw Tom Scott's video on FizzBuzz https://www.youtube.com/watch?v=QPZ0pIK_wsc so I felt to write my own more "complex" version,this is what I came up with, its very flexibly and easy to scale, and ...
-3
votes
1answer
438 views

Four In A Row: AI Tournament [duplicate]

Four-In-A-Row AI Tournament Today, we will be playing a Four-In-A-Row tournament. However, it is not us humans playing... instead, we must have our computers battle instead! This challenge is ...
11
votes
1answer
529 views

C# First 1 (right to left) in binary number

I am trying to use C# to find the index of the first 1 (right to left) in the binary representation of a number. For example, since 100 in binary is: 0b1100100 ...
5
votes
2answers
488 views

Create another empty string in .NET? [closed]

I apologize if this isn't fit for this site but it is a puzzle, not all that practical, so I thought it would fit. Take this code: ...
11
votes
3answers
946 views

C# is the Main problem

This programming puzzle is inspired by another question which has been asked here yesterday but which was deleted by the author... The challenge: Create an executable binary (Windows .EXE or Linux ...
1
vote
1answer
628 views

Make a better score than my students! [closed]

For the last day of the semester, I decided to have some fun with my students and I showed them Code Golf... poor guys, they're addicted now. The goal was to compete against the other students to ...
20
votes
1answer
2k views

A little bool magic

Challenge Given the following C# method: ...
4
votes
0answers
622 views

C# program containing `? null :` that is still valid without `null` [closed]

I found an old post on Jon Skeet's blog that pointed out a puzzle from a tweet by Vladimir Reshetnikov: C# quiz: write a valid C# program containing a sequence of three tokens ...
8
votes
3answers
2k views

Convert a string representation of a number to int[] in C#

What is the shortest C# statement that will convert a string representation of a number to an int[] that contains each digit? ...
7
votes
4answers
2k views

Leibniz golf in C#

I'm starting with golf code. But im only do C# so I know wont be a breaking record, but I want give it a try. Leibniz Challenge is here The first line contains the number of test cases (N) which is ...
-1
votes
2answers
455 views

Make the function comparing two variables with different value print True [closed]

Without changing the actual function, call it in such a way that it prints "True" ...
-4
votes
1answer
546 views

Throwing uncatchable ExecutionEngineException

The shortest C# code that generates an uncatchable ExecutionEngineException wins. You are not allowed to call FailFast directly or indirectly.
18
votes
6answers
2k 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 ...
2
votes
10answers
4k views

Can you cancel the stackoverflow exception in the following code? [closed]

The following code will produce a run-time error, stackoverflow exception. ...
15
votes
6answers
4k 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. ...
2
votes
2answers
976 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 ...
3
votes
1answer
800 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# ...
22
votes
1answer
2k 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: ...
-9
votes
4answers
835 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: ...
2
votes
1answer
757 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. ...
1
vote
2answers
326 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 ...
14
votes
5answers
6k 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 ...
61
votes
50answers
13k 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 ...