mirror of
https://github.com/LeCoupa/awesome-cheatsheets.git
synced 2025-11-08 14:01:35 +00:00
fix spelling and whitespace in cheatsheets
This commit is contained in:
@@ -3,7 +3,7 @@ CHEATSHEET C#
|
||||
1. Data Types
|
||||
|
||||
Primitive Size Example
|
||||
|
||||
|
||||
String 2 bytes/char s = "reference";
|
||||
bool b = true;
|
||||
char 2 bytes ch = 'a';
|
||||
@@ -16,20 +16,20 @@ CHEATSHEET C#
|
||||
decimal 16 bytes val = 70.0M;
|
||||
|
||||
2. Arrays
|
||||
|
||||
|
||||
2.1 Declaration
|
||||
|
||||
//Initiliazed using a list defined with curly braces
|
||||
int[] nameArray = {100, 101, 102};
|
||||
|
||||
|
||||
//Define an empty array
|
||||
int[] nameArray = new int[3]; // 3 rows and 2 columns
|
||||
|
||||
|
||||
//To access a specific item in the array
|
||||
int[] nameArray = new int[10];
|
||||
int firstNumber = nameArray[0];
|
||||
nameArray[1] = 20;
|
||||
|
||||
|
||||
//Multidimensional arrays
|
||||
int [,] matrix = new int [2,2]
|
||||
matrix[0,0] = 1;
|
||||
@@ -40,26 +40,26 @@ CHEATSHEET C#
|
||||
int[,] predefinedMatrix = new int[2,2] { { 1, 2 }, { 3, 4 } };
|
||||
|
||||
2.2 Array Operations
|
||||
|
||||
|
||||
//Sort ascending
|
||||
Array.Sort(nameArray);
|
||||
|
||||
|
||||
//Sort begins at element 6 and sorts 20 elements
|
||||
Array.Sort(nameArray,6,20);
|
||||
|
||||
|
||||
//Use 1 array as a key & sort 2 arrays
|
||||
string[] values = {"Juan", "Victor", "Elena"};
|
||||
string[] keys = {"Jimenez", "Martin", "Ortiz"};
|
||||
Array.Sort(keys, values);
|
||||
|
||||
|
||||
//Clear elements in array (array, first element, # elements)
|
||||
Array.Clear(nameArray, 0, nameArray.Length);
|
||||
|
||||
|
||||
//Copy elements from one array to another
|
||||
Array.Copy(scr, target, numOfElements);
|
||||
|
||||
3. String Operations
|
||||
|
||||
|
||||
//To concatenate between strings, use the plus operator:
|
||||
string firstName = "Erin";
|
||||
string lastName = "Roger";
|
||||
@@ -68,27 +68,27 @@ CHEATSHEET C#
|
||||
//To add one string to another, use the += operator:
|
||||
string secondLastName = "Green";
|
||||
string fullName += secondLastName;
|
||||
|
||||
|
||||
//ToString function
|
||||
//It converts an object to its string representation so that it is suitable for display
|
||||
Object.ToString();
|
||||
|
||||
|
||||
//String formatting
|
||||
//Each additional argument to the function can be referred to in the string using the brackets operator with the index number.
|
||||
String.Format(String format, Object arg0);
|
||||
format - A composite format string that includes one or more format items
|
||||
format - A composite format string that includes one or more format items
|
||||
arg0 - The first or only object to format
|
||||
|
||||
//Substring
|
||||
//Returns a part of the string, beginning from the index specified as the argument. Substring also accepts a maximum length for the substring
|
||||
String.Substring(beginAt);
|
||||
String.Substring(beginAt, maximum);
|
||||
|
||||
|
||||
//Replace
|
||||
string newStr = oldStr.Replace("old","new");
|
||||
|
||||
//IndexOf
|
||||
//Finds the first ocurrence of a string in a larger string
|
||||
//Finds the first occurrence of a string in a larger string
|
||||
//Returns -1 if the string is not found
|
||||
String.IndexOf(val, start, num)
|
||||
val - string to search for
|
||||
@@ -102,7 +102,7 @@ CHEATSHEET C#
|
||||
String.Split(Char[]);
|
||||
|
||||
//ToCharArray
|
||||
//Places selected characteres in a string in a char array
|
||||
//Places selected characters in a string in a char array
|
||||
String str = "AaBbCcDd";
|
||||
//create array of 8 vowels
|
||||
var chars = str.ToCharArray();
|
||||
@@ -132,11 +132,11 @@ CHEATSHEET C#
|
||||
DateTime nextYear = DateTime.AddYears(1);
|
||||
|
||||
6. TimeSpan
|
||||
|
||||
|
||||
6.1 TimeSpan Constructor
|
||||
|
||||
TimpeSpan(hour, minute, sec)
|
||||
|
||||
|
||||
TimeSpan(hour, minute, sec)
|
||||
|
||||
TimeSpan timeS = new TimeSpan(10, 14, 50);
|
||||
TimeSpan timeS_Hours = TimeSpan.FromDays(3640);
|
||||
|
||||
@@ -144,8 +144,8 @@ CHEATSHEET C#
|
||||
|
||||
Format item syntax: {index[,alignment][:format string]}
|
||||
index - Specifies element in list of values to which format is applied
|
||||
aligment - Indicates minimun width (in characters) to display value
|
||||
format string - Contains the code which specififes the format of the displayed value
|
||||
alignment - Indicates minimum width (in characters) to display value
|
||||
format string - Contains the code which specifies the format of the displayed value
|
||||
|
||||
7.1 Numeric
|
||||
|
||||
@@ -168,7 +168,7 @@ CHEATSHEET C#
|
||||
csc -define:DEBUG -optimize -out:File2.exe *.cs -> Compiles all the C# files in the current directory with optimizations enabled and defines the DEBUG symbol. The output is File2.exe
|
||||
csc -target:library -out:File2.dll -warn:0 -nologo -debug *.cs -> Compiles all the C# files in the current directory producing a debug version of File2.dll. No logo and no warnings are displayed
|
||||
csc -target:library -out:Something.xyz *.cs -> Compiles all the C# files in the current directory to Something.xyz (a DLL)
|
||||
|
||||
|
||||
8.1 Compiler Options Listed
|
||||
|
||||
Option Purpose
|
||||
@@ -260,21 +260,21 @@ CHEATSHEET C#
|
||||
10. Loop
|
||||
|
||||
10.1 While
|
||||
|
||||
|
||||
while (condition) {body}
|
||||
|
||||
|
||||
10.2 Do while
|
||||
|
||||
do {body} while condition;
|
||||
|
||||
|
||||
10.3 For
|
||||
|
||||
for (initializer; termination condition; iteration;) {
|
||||
//statements
|
||||
}
|
||||
|
||||
|
||||
10.4 For each
|
||||
|
||||
|
||||
foreach (type identifier in collection) {
|
||||
//statements
|
||||
}
|
||||
@@ -293,7 +293,7 @@ CHEATSHEET C#
|
||||
[access modifier] className (parameters) [:initializer]
|
||||
|
||||
initializer -base calls constructor in base class.
|
||||
this calls constuctor within class.
|
||||
this calls constructor within class.
|
||||
|
||||
public class nameClass : Initializer {
|
||||
public className(dataType param1 , dataType param2, ...) : base(param1, param2)
|
||||
@@ -313,8 +313,8 @@ CHEATSHEET C#
|
||||
abstract – must be implemented by subclass
|
||||
|
||||
Passing parameters:
|
||||
1. By default, parametres are passed by value
|
||||
2. Passing by reference: ref, in and out modifers
|
||||
1. By default, parameters are passed by value
|
||||
2. Passing by reference: ref, in and out modifiers
|
||||
|
||||
To pass a parameter by reference with the intent of changing the value, use the ref, or out keyword. To pass by reference with the intent of avoiding copying but not changing the value, use the in modifier
|
||||
|
||||
@@ -331,9 +331,9 @@ CHEATSHEET C#
|
||||
12. Struct
|
||||
|
||||
12.1 Defining a structure
|
||||
|
||||
|
||||
[attribute][modifier] struct name [:interfaces] { struct-body }
|
||||
|
||||
|
||||
12.2 Class vs Structure
|
||||
|
||||
-> Classes are reference types and structs are value types
|
||||
@@ -378,7 +378,7 @@ CHEATSHEET C#
|
||||
//To declare an event inside a class, first a delegate type for the event must be declared.
|
||||
|
||||
public delegate string MyDelegate(string str);
|
||||
|
||||
|
||||
//The event itself is declared by using the event keyword
|
||||
|
||||
event MyDelegate MyEvent;
|
||||
|
||||
Reference in New Issue
Block a user