Archive

Archive for the ‘csharp’ Category

C# is awesome

April 12, 2018 Leave a comment

I started to play with C# and I really enjoy it. I found a great book that explains the concepts very well: The C# Player’s Guide by RB Whitaker. I found the 2nd edition in our library but it also has a 3rd edition.

I started a C# project, which is a collection of custom extensions. You can find it here: https://github.com/jabbalaci/JabbaCustomExtensions-for-C-Sharp.

I also have a little utility (written in Python) that facilitates C# development under Linux in the command-line: https://github.com/jabbalaci/C-Sharp-CLI-Helper.

I’m playing with C# under Linux. JetBrains has a cross-platform IDE for .NET called Rider. It works very well for me.

Links

Advertisements
Categories: book, csharp

pretty print a C# source code

March 29, 2018 Leave a comment

Problem
I wanted to print the page at https://learnxinyminutes.com/docs/csharp/, but the produced PDF was black and white, i.e. the syntax highlighting was lost. How to print a source code with colors?

Solution
I tried several browsers, several editors, but nothing worked. Then I found a LaTeX solution. The necessary files and the produced PDF output are here: https://github.com/jabbalaci/blog-assets/tree/master/20180329-print-CSharp-code.

I put here the LaTeX source:

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
%% Define your header here.
%% See http://texblog.org/2007/11/07/headerfooter-in-latex-with-fancyhdr/
\fancyhead[CO,CE]{C\# Summary}

\usepackage[usenames,dvipsnames]{color}  %% Allow color names

%% The listings package will format your source code
\usepackage{listings}
\lstdefinestyle{customasm}{
  belowcaptionskip=1\baselineskip,
  xleftmargin=\parindent,
  language={[Sharp]C},
  breaklines=true, %% Wrap long lines
  basicstyle=\footnotesize\ttfamily,
  commentstyle=\itshape\color{Gray},
  stringstyle=\color{Black},
  keywordstyle=\bfseries\color{OliveGreen},
  identifierstyle=\color{blue},
  xleftmargin=-8em,
  showstringspaces=false
}
\begin{document}

\lstinputlisting[style=customasm]{src.cs}

\end{document}

The LaTeX tip is from here.

Categories: csharp, latex Tags:

[manjaro] Make C# debugger work in Visual Studio Code

Problem
Under Manjaro / Arch you use Visual Studio Code with the C# extension. Everything works fine except the C# debugger.

Solution
I found the solution here: https://github.com/OmniSharp/omnisharp-vscode/issues/1323 . The debugger on Manjaro / Arch is not supported officially, so we need to do some tricks. In VS Code open the user settings and add this line:

"csharp.fallbackDebuggerLinuxRuntimeId": "ubuntu.16.04-x64"

Uninstall the C# extension, restart VS Code, and re-install the C# extension. Open a .cs file and the extension will download some packages, including the debugger for Ubuntu 16.04 (as we specified it in the settings).

However, the *.so files of the Ubuntu debugger rely on a specific version of the package “icu”.

$ cd ~/.vscode/extensions/ms-vscode.csharp-1.11.0/.debugger
$ find *.so -type f | xargs ldd 2> /dev/null | grep not\ found
        liblldb-3.6.so => not found
        libvsdebugeng.so => not found
        libvsbaseservices.so => not found
        libvsbaseservices.so => not found
        libicuuc.so.55 => not found
        libicui18n.so.55 => not found

The last 2 lines are interesting: we need version 55 of the package “icu“. “yaourt icu” revealed that I had version 59 installed, but version 55 can be installed too with “yaourt icu55“. The two versions can co-exist. When installed, restart VS Code and debugging should work now.

Credits
The solution was found at https://github.com/OmniSharp/omnisharp-vscode/issues/1323 . A big thanks for starquake.

Categories: csharp, manjaro Tags:

In C#, ++c and c += 1 are not always equivalent

July 2, 2017 1 comment
csharp> char c = 'a'
csharp> ++c
'b'
csharp> c += 1
(1,7): error CS0031: Constant value `1' cannot be converted to a `char'
csharp>
Categories: csharp Tags: ,