📜 ⬆️ ⬇️

C #: Etudes, part 2

Continued, start here.

I’ll start with a poll: how do you know how to execute the code before the start of the Main () function (I hope that I will list all the unknown people and a couple of unknowns :))?

And now the problem:

Before you is a small code that displays two characters (by the way, check yourself: in what order will they appear?). It is necessary to display the underscore "_" between these characters.
Of course, the task would be trivial without restrictions. And they are as follows:

  • do not define another method Main
  • do not use the Console identifier as a class name, property, field, etc. (thanks to the irc-user Gopneg)
  • do not change the code of all existing methods: App.Main, XX, YY
  • do not change the definition of the Xy field
  • do not add new fields to class X


using System;<br><br> class Y<br>{<br> public Y()<br> {<br> Console .Write( "0" );<br> }<br>}<br><br> class X<br>{<br> public X()<br> {<br> Console .Write( "o" );<br> }<br> Y y = new Y();<br>}<br><br> class App<br>{<br> static void Main()<br> {<br> X x = new X();<br> }<br>}<br> <br> * This source code was highlighted with Source Code Highlighter .

')
Good luck!

PS
So, we have two winners: mace was the first and guessed the author's solution: http://habrahabr.ru/blogs/net/77039/#comment_2241079
and the habrayuzer bobermaniac suggested an elegant way to bypass my restriction on the Console override: http://habrahabr.ru/blogs/net/77039/#comment_2241109

By the way, the question of calling the code before Main is still relevant! While the most obvious is offered - the static class constructor.

Pps
Suddenly, another solution was proposed by SHSE : http://habrahabr.ru/blogs/net/77039/#comment_2243183 , and it is based on very different mechanisms, but it works great! )

Source: https://habr.com/ru/post/77039/


All Articles