• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/53

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

53 Cards in this Set

  • Front
  • Back
  • 3rd side (hint)

CLR

Common Language Runtime

C#

Programming Language

. NET

Framework for building applications on windows. .Net is not limited to C# and different languages such as VB or F#. It consists of CLR and a class library that we use for building applications.

CLRs job is?

Translate intermediate language code into machine code, called JIT or just in time compilation.

C# is compiled into?

Common Intermediate Language, it is byte code, a platform independent instruction set that can be executed in any environment.

Namespace

Container for related classes

Assembly

Container for related namespaces. It can be a dll or exe on disk. It's a single unit of deployment of. NET application. When you compile you are making an assembly.

DLL

Dynamically Linked Library

What are System, System.Core, System.XML?

Assemblies because they are dlls but they are also namespaces.

JIT compilation

The compilation of intermediate language code to native machine code by CLR, common language runtime, a virtual machine component of .NET.

Constant

An immutable value

Variable

A name given to a storage location in memory.

Why use constants?

For protection against changing, for safety.

Byte, how many bytes and range?

1 byte, 0 to 255

short

2 bytes, - 32,768 to 32,768

int

4 bytes, -2,1b to 2.1b

long

8 bytes

decimal

16 bytes, -7.9x10^28 to 7.9x10^28 real number, suffix is m


decimal dec = 4.5m;

bool

1 byte

Double

8 bytes, real number

char

2 bytes, unicode

Overflowing

exceeding the boundary of the datatype, to stop this use the checked keyword, this will throw an exception!



checked


{


byte number = 255;


number+=1;


}

Scope

Is where the variable is visible, so which part of the program can see the variable.

var


An implicit type and strongly typed variable where the compiler determines the type.

Format String

Console.WriteLine("{0} {1} {2}", var1, var2, var3);



A template of variables to substitute

Implicit type conversion

byte b = 1;


int i = b;



No problem converting because byte is smaller than int. So the compiler can convert implicitly.

Explicit type conversion or casting

int i = 1;


byte b = i;


Won't compile needs a cast or explicit conversion.


int i = 1;


byte b = (byte) i;



But this only works with convertible types.

How to convert string to int?

string s = "2";


int i = Convert.ToInt32(s);


int j = int.Parse(s);


Prefer Convert over int.Parse because int.Parse will throw an exception instead of returning null like Convert if the input is bad.

Post fix, prefix incriment


int a =1;


int b = a++;


int c = ++b;

a=2


b=2


c=2

Will byte b = 500; compile?

No because the compiler will check that it is between 0 and 255.

Static modifier on main ?

No need to create an object to call a static method. Static says there is only one instance. So 1 main function, which is why main is static and why you can call it from the class name.

Struct vs class

Structs can't have default constructor, so no parameterless constructor.


Structs are value type and are copied, classes are reference type.


Structs can be instantiated without using new.


Structs cannot inherit.


Structs are allocated on the stack.


Classes are created on the heap.

Declaring arrays allows for different syntax.

string[] names = {"Ralph", "Jake"} ;


string[] names = new string[] {"Ralph", "Jake"} ;


string[] names = new string[2] {"Ralph", "Jake"} ;


string[] names = new string[2];

Are strings immutable?

Yes, you need to create a new one to change it.

How to create a verbatim string to not need escape backslash?

Put an @ symbol in front of the string?

String vs string


Int32 vs int


String in System assembly or namespaces is the same as the keyword string.


Same for Int32 and int

Can enums use something other than int?

Yes


enum Temperature : byte


enum Temperature : short


enum Temperature : long


enum Temperature : ulong

How to convert a string to enum?

Enum.Parse(typeof(myenum), mystring);

Arrays when copy, copy by reference or value?

Copy by reference!


int[] myints = new int[1] {2};


int[] sameints = myints;

What are Span<T> and Memory<T>

A data structure that allows you access contiguous memory. You can test, change and convert elements in memory.


Span is on the stack, Memory is on the heap.


Span is not implemented in unity, but there is a way to get Memory. Can reuse memory with Memory by slicing.


We can edit inside of foreach loops when referencing value types which isn't available in List.

Seed a random number generator?

Random rand = new Random(Guid.NewGuid().GetHasCode());

Difference between jagged array and rectangular array?

int[,] array2d = new int[1,5];


Vs


int[,] array2d = new int[2,];


array2d[0] = new int[8];


array2d[1] = new int[2];

When subtracting timespans in C# what does it give you?

The difference in time between timespans.

How to convert a string to a timespans?

TimeSpan.Parse("01:02:03")


Will create a time span with 1 hour 2 minutes and 3 seconds.

How do you get the current time?

DateTime.Now

Since DateTime is immutable what must you do to add time?

DateTime dt = oldDT.AddYears(1)


Always return a new instance.



oldDT has not changed

How to create a time span of 5 hours?

TimeSpan.FromHours(5)

How to get the current year?

DateTime.Now.Year

How to get rid of white space at the end or beginning?

Trim

To replace a given character or substring use?

String.Replace("are", "aren't");

How to tell string to format a number to currency with dollar sign?

Convert a number to currency, or dollars.

int i = 1234;


i.ToString("C");


C is for currency.

How to split strings on spaces?

car names = Mystring.Split(" ");

Best way to check if the string is good?

String.IsNullOrEmpty(mystring);