\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{PaolaP (pao361)} \pdfinfo{ /Title (c-cheatsheet.pdf) /Creator (Cheatography) /Author (PaolaP (pao361)) /Subject (C\# CheatSheet Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{0812A3} \definecolor{LightBackground}{HTML}{F7F7FC} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{C\# CheatSheet Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{PaolaP (pao361)} via \textcolor{DarkBackground}{\uline{cheatography.com/140352/cs/29786/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}PaolaP (pao361) \\ \uline{cheatography.com/pao361} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 8th January, 2022.\\ Updated 19th November, 2021.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{x{1.84149 cm} x{3.13551 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Data Types}} \tn % Row 0 \SetRowColor{LightBackground} string & 2 bytes/char \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{bool} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} char & 2 bytes \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} byte & 1 byte \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} short & 2 bytes \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} int & 4 bytes \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} long & 8 bytes \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} float & 4 bytes \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} double & 8 bytes \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} decimal & 16 bytes \tn % Row Count 10 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Float: Can hold up to seven significant digits of accuracy \newline Double: Can hold 15 or 16 significant digits of accuracy \newline Decimal: Has a greater precision and a smaller range. Suitable for financial and monetary calculations} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Displaying Variable Values}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{using System; \newline public class DisplaySomeMoney \newline {[} \newline public static void Main() \newline \{ \newline double someMoney = 39.45; \newline \seqsplit{Console.WriteLine(someMoney);} \newline \} \newline {[}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4177 cm} x{1.62903 cm} p{0.4177 cm} x{1.71257 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Operators}} \tn % Row 0 \SetRowColor{LightBackground} + & Addition & - & Subtraction \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} * & Multiplication & / & Division \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \% & Remainder & & \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Suffixes}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Put an F after a number to make it a float}} \newline % Row Count 1 (+ 1) ~float pocketchange = 4.87F; \newline % Row Count 2 (+ 1) {\bf{Put a D after it to make it a double (default)}} \newline % Row Count 4 (+ 2) ~float pocketchange = 4.87D; \newline % Row Count 5 (+ 1) {\bf{Put an M (money) after it to make it a decimal}} \newline % Row Count 7 (+ 2) ~ float pocketchange = 4.87M; \newline % Row Count 8 (+ 1) {\bf{Scientific notation}} \newline % Row Count 9 (+ 1) ~Includes an E (for exponent)% Row Count 10 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Methods}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Define it – takes 4 steps \newline % Row Count 1 (+ 1) ~Declaration (or method header, or signature) \newline % Row Count 3 (+ 2) ~\{ \newline % Row Count 4 (+ 1) ~Code (method body) \newline % Row Count 5 (+ 1) ~~Return value; \newline % Row Count 6 (+ 1) ~\} \newline % Row Count 7 (+ 1) Call it (invoke it)% Row Count 8 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Method declarations}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Method with no return value, and passes no parameters}} \newline % Row Count 2 (+ 2) public static {\bf{void}} DisplayHelloText() \newline % Row Count 3 (+ 1) ~DisplayHelloText(); \newline % Row Count 4 (+ 1) {\bf{Method with no return value, and passes one parameter}} \newline % Row Count 6 (+ 2) public static {\bf{void}} DisplaySalesTax(double {\emph{pAmt}}) \newline % Row Count 8 (+ 2) \seqsplit{ ~DisplaySalesTax(1243.00);} \newline % Row Count 9 (+ 1) {\bf{Method with no return value, and passes two parameters}} \newline % Row Count 11 (+ 2) public static {\bf{void}} DisplaySalesTax(double {\emph{pAmt}}, double {\emph{ptaxRate}}) \newline % Row Count 13 (+ 2) ~DisplaySalesTax (1243.00, .09); \newline % Row Count 14 (+ 1) {\bf{Method that returns a value, and passes two parameters}} \newline % Row Count 16 (+ 2) public static {\bf{double}} DisplaySalesTax(double {\emph{pAmt}}, double {\emph{ptaxRate}}) \newline % Row Count 18 (+ 2) ~Amount = DisplaySalesTax (1243.00, .09); \newline % Row Count 20 (+ 2) ~return {\emph{Answer}};% Row Count 21 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{(if no return, then {\bf{void}}, else, return type, e.g. integer32, string, double, etc)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.45947 cm} x{1.6708 cm} p{0.4177 cm} x{1.62903 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Convert Methods}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{ToBoolean()} & to an equivalent Boolean value & \seqsplit{ToInt16()} & to a 16-bit signed integer \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \seqsplit{ToByte()} & to an 8-bit unsigned integer & \seqsplit{ToInt32()} & to a 32-bit signed integer \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{ToChar()} & to a Unicode character & \seqsplit{ToInt64()} & to a 64-bit signed integer \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{ToDecimal()} & to a decimal number & \seqsplit{ToString()} & to its equivalent String representation \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{ToDouble()} & to a \seqsplit{double-precision} floating-point number & \seqsplit{ToUInt16()} & to a 16-bit unsigned integer \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Arrays Functions}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Array.Sort(arrayName)} & Arranges array items in ascending order \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Array.Length & Length of the array \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \seqsplit{Array.Reverse(arrayName)} & Reverses the order of items in an array \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{Array.BinarySearch(ArrayName}, value) & Finds a requested value in a sorted array \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Do not use BinarySearch() under these circumstances \newline If your array items are not arranged in ascending order \newline If your array holds duplicate values and you want to find all of them \newline If you want to find a range match rather than an exact match} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Array}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Assigning values to array elements}} \newline % Row Count 1 (+ 1) `double{[}{]} sales = new double{[}20{]};` \newline % Row Count 2 (+ 1) `sales{[}0{]} = 2100.00;` \newline % Row Count 3 (+ 1) `sales{[}1{]} = 3256.06;` \newline % Row Count 4 (+ 1) {\bf{Printing an element value}} \newline % Row Count 5 (+ 1) `Console.WriteLine(sales{[}1{]});` \newline % Row Count 6 (+ 1) **for loop to search a Parallel Array \newline % Row Count 7 (+ 1) `for (int i = 0; i \textless{} nameArray.Length; i++)` \newline % Row Count 8 (+ 1) `\{` \newline % Row Count 9 (+ 1) ` if (nameArray{[}i{]} == dwarfName)` \newline % Row Count 10 (+ 1) ` \{` \newline % Row Count 11 (+ 1) ` {\emph{do something}}` \newline % Row Count 12 (+ 1) ` \}` \newline % Row Count 13 (+ 1) `\}`% Row Count 14 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Multidimensional Arrays}} \tn % Row 0 \SetRowColor{LightBackground} One-dimensional or single-dimensional array & Picture as a column of values. Elements can be accessed using a single subscript \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} Multidimensional arrays & Require multiple subscripts to access the array elements \tn % Row Count 7 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Conditional Operators}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Conditional AND operator}} \newline % Row Count 1 (+ 1) -Determines whether two expressions are both true \newline % Row Count 2 (+ 1) -Written as two ampersands (\&\&) \newline % Row Count 3 (+ 1) -You must include a complete Boolean expression on {\bf{each side}} of the operator \newline % Row Count 5 (+ 2) Written as `If (age \textgreater{}= 0 \&\& age \textless{} 120) ` \newline % Row Count 6 (+ 1) {\bf{Conditional OR operator}} \newline % Row Count 7 (+ 1) Used when you want some action to occur even if only one of two conditions is true \newline % Row Count 9 (+ 2) Written as `if (a == 1 || b+c \textgreater{} 3)`% Row Count 10 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Loops}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{if stataments}} \newline % Row Count 1 (+ 1) if ({\emph{statement}}) \newline % Row Count 2 (+ 1) \{ \newline % Row Count 3 (+ 1) ~ {\emph{do something}} \newline % Row Count 4 (+ 1) \} \newline % Row Count 5 (+ 1) {\bf{while loop}} \newline % Row Count 6 (+ 1) while ({\emph{statement}}) \newline % Row Count 7 (+ 1) \{ \newline % Row Count 8 (+ 1) ~ {\emph{do something}} \newline % Row Count 9 (+ 1) \}//end loop \newline % Row Count 10 (+ 1) -Definite loop or counted loop \newline % Row Count 11 (+ 1) Loop for which the number of iterations is predetermined \newline % Row Count 13 (+ 2) -Indefinite loop \newline % Row Count 14 (+ 1) Value of a loop control variable is not altered by arithmetic, but instead, is altered by user input (ask user a question inside the loop, exit based on a particular answer) \newline % Row Count 18 (+ 4) {\bf{do-while loop}} \newline % Row Count 19 (+ 1) do \newline % Row Count 20 (+ 1) \{ \newline % Row Count 21 (+ 1) ~ {\emph{do something in the loop}} \newline % Row Count 22 (+ 1) \} \newline % Row Count 23 (+ 1) while ({\emph{statement}}) \newline % Row Count 24 (+ 1) {\bf{for loop}} \newline % Row Count 25 (+ 1) When using a for statement, you can indicate in one place: \newline % Row Count 27 (+ 2) Starting value for the loop control variable \newline % Row Count 28 (+ 1) Test condition that controls loop entry \newline % Row Count 29 (+ 1) Expression that alters the loop control variable \newline % Row Count 30 (+ 1) } \tn \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Loops (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{for ({\emph{statement}}) \newline % Row Count 1 (+ 1) {\emph{do something}}% Row Count 2 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.88666 cm} x{2.09034 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{DateTime and TimeSpan}} \tn % Row 0 \SetRowColor{LightBackground} DateTime(yr, mo,day) & \seqsplit{currdt.AddDays(1)} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} DateTime(yr, mo,day, hr, min, sec) & \seqsplit{currdt.SubtractDays(1)} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{DateTime.Parse("1/1/2015")} & TimeSpan(hrs,min,sec) \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} DateTime.Now & \seqsplit{TimeSpan.FromSeconds(120)} \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}