Open gustavo-fior opened 1 year ago
as far as I searched, there's no available version of visual studio (not vs code) for Linux :/
using System.IO;
using DataTier = Acme.SQLCode.Client;
namespace AcmeAccounting
{
public class GetDetails
{
// ...
}
}
namespace AcmeFinance
{
public class ShowDetails
{
// ...
}
}
Short Name | .NET Class | Type | Width | Range (bits) |
---|---|---|---|---|
byte | Byte | Unsigned integer | 8 | 0 to 255 |
sbyte | SByte | Signed integer | 8 | -128 to 127 |
int | Int32 | Signed integer | 32 | -2,147,483,648 to 2,147,483,647 |
uint | UInt32 | Unsigned integer | 32 | 0 to 4294967295 |
short | Int16 | Signed integer | 16 | -32,768 to 32,767 |
ushort | UInt16 | Unsigned integer | 16 | 0 to 65535 |
long | Int64 | Signed integer | 64 | -9223372036854775808 to 9223372036854775807 |
ulong | UInt64 | Unsigned integer | 64 | 0 to 18446744073709551615 |
float | Single | Single-precision floating point type | 32 | -3.402823e38 to 3.402823e38 |
double | Double | Double-precision floating point type | 64 | -1.79769313486232e308 to 1.79769313486232e308 |
char | Char | A single Unicode character | 16 | Unicode symbols used in text |
bool | Boolean | Logical Boolean type | 8 | True or false |
object | Object | Base type of all other types | ||
string | String | A sequence of characters | ||
decimal | Decimal | Precise fractional or integral type that can represent decimal numbers with 29 significant digits | 128 | ±1.0 × 10e−28 to ±7.9 × 10e28 |
public enum Color
{
Green, //defaults to 0
Orange, //defaults to 1
Red, //defaults to 2
Blue //defaults to 3
}
public enum Color2
{
Green = 10,
Orange = 20,
Red = 30,
Blue = 40
}
String literals:
static void Main()
{
//Using escaped characters:
string path1 = "\\\\FileShare\\Directory\\file.txt";
System.Console.WriteLine(path1);
//Using String Literals:
string path2 = @"\\FileShare\Directory\file.txt";
System.Console.WriteLine(path2);
}
in c# we have:
int i = 10;
int k = i;
i = 30;
System.Console.WriteLine(i); // 30 System.Console.WriteLine(k); // 10
- **type reference** -> will point to the same object, which means if you made a change through ee2, ee1 will also be updated
```cs
Employee ee1 = new Employee();
Employee ee2 = ee1;
Category | Symbol |
---|---|
Type of Operand | typeof |
Size of Operand | sizeof |
Enforce Overflow Checking | checked |
Suppress Overflow Checking | unchecked |
class TestCheckedAndUnchecked
{
static void Main()
{
short a = 10000;
short b = 10000;
short c = (short)(a * b); // unchecked by default
short d = unchecked((short)(10000 * 10000)); // unchecked
short e = checked((short)(a * b)); // checked - run-time error
System.Console.WriteLine(10000 * 10000); // 100000000
System.Console.WriteLine(c); // -7936
System.Console.WriteLine(d); // -7936
System.Console.WriteLine(e); // no result
}
}
you need to specify what you want to do at the end of the case (e.g. break; or goto case "idk";)
static void Main(string[] args)
{
switch (args[0])
{
case "copy":
//...
break;
case "move":
//...
goto case "delete";
case "del":
case "remove":
case "delete":
//...
break;
default:
//...
break;
}
}
static void Main()
{
string[] arr= new string[] {"Jan", "Feb", "Mar"};
foreach (string s in arr)
{
System.Console.WriteLine(s);
}
}
public Visible to all.
protected Visible only from derived classes.
private DEFAULT Visible only within the given class.
internal Visible only within the same assembly.
protected internal Visible only to the current assembly or types derived from the containing class.
sealed (structs) The class can´t be inherited.
readonly / const
Create constants like final
in Java. Can only assign in constructor or declaration.
static int Main(string[] args)
{
//...
return 0;
}
if a parameter is a primitive, it will be passed as a value, if it's an object it will be passed as a reference. if you want to pass primitives as reference, use keyword out or ref.
you can pass a indeterminate number of params for a function like this:
class TestParams
{
private static void Average(string title, params int[] values)
{
int sum = 0;
System.Console.Write("Average of {0} (", title);
for (int i = 0; i < values.Length; i+)
{
sum += values[i];
System.Console.Write(values[i] + ", ");
}
System.Console.WriteLine("): {0}", (float)sum/values.Length);
}
static void Main()
{
Average ("List One", 5, 10, 15);
Average ("List Two", 5, 10, 15, 20, 25, 30);
}
}
I've been coding in Java for couple of years now, so my notes are gonna be based on the differences between Java and C#