Data Types Flashcards
Namespace
Namespaces provide a hierarchical means of organizing C# programs and libraries.
Namespaces contain types and other namespaces—for example, the System namespace contains many types, such as the Console class referenced in the program, and many other namespaces, such as IO and Collections
using
A using directive that references a given namespace enables unqualified use of the types that are members of that namespace.
Because of the using directive, the program can use Console.WriteLine as shorthand for System.Console.WriteLine
Access Modifiers
- public: Access isn’t restricted.
- private: Access is limited to the containing type, only in same class
- file: The declared type is only visible in the current source file.
File scoped types are generally used for source generators. - internal: Access is limited to the current assembly.- only in assembly, same namespace/ project
- protected: Access is limited to the containing class
or types derived from the containing class- class and the classes
that derived from it
2 types of protected acess modifiers
proteced: private and internal
- private protected: Access is limited to the containing class or
types derived from the containing class within the current assembly - protected internal: Access is limited to the current
assembly or types derived from the containing class.
W C# oraz .NET, assembly to podstawowy blok wykonywalny aplikacji, który może być plikiem wykonywalnym (.exe) lub biblioteką (.dll).
Assembly to jednostka wdrożenia, która zawiera kod, zasoby, a także informacje o metadanych niezbędne do wykonania tego kodu.
Termin current assembly odnosi się do tego konkretnego assembly, w którym aktualnie znajduje się kod, czyli kod wykonujący się w danym momencie. Jest to po prostu assembly, w którym znajduje się definicja klasy lub członka, którego dotyczy kontrola dostępu.
2 types of values
based on how they occupy the memory
1. value type
2. reference type
value type
stored directly
typically stored in stack
reference type
stores the memory location of data, variable
stores memory reference, not value directly
value type
- primitives
- nullable version
- struct
- enum
reference type
- class
- interface
- array
- delegates
- string
acdis
Primitive data types
- integral- sbyte, short, integer, long
- floating point- float, double, decimal
- boolean-bool
- unicode characters
2 types of conversion
implicit- no risk of losing data
explicit- with risk of losing data, double to int
var
-from c# 3.0, to declare local variables
-compiler determines the data type
-cannot be null
Encapsulation
Encapsulation- practice of hiding the internal state of an object and allowing access and modification through methods
-Data integrity
-Reduce complexity
-Abstraction- hide the implementation details
Private field logic
public property- getters and setters accessors, control access
auto-implemented properties
automaticlly creates a field ,
automaticlly creats a getter and a setter
Finalizer/Destructor
-
class can have only one finalizer, define with ~, cannot be overloaded or inherited
-when object is destroyed, is out of scoped
-cleanup statement
Inheritance
define a class within another class,
A class can inherint from a single class and multiple interfaces
virtual keyword
can be overridden in classes that inherits from this class
then we use override keyword
Polymorhpish
using new keyword in the method is not a overrridening but giving higher priority
sealed keyword-
the method or a class cannot be overridden
abstract class
class- cannot create an instance of abstract class, just the blueprint
method- a method that has to be implemented!
to compare if is an instance of a class-
as/ is keyword
Cube iceCube = element as Cube
if element is Cube
Abstract classes and interfaces
cant create an instance of it
both support polymorphism
Abstract classes and interfaces compare
Abstract classes:
can have constructor
can be partially implemented
can contain fields
only one inherit
-> AND Interfaces cant and class implement many
Reading a file
System.IO.File.ReadAllText
Writing to a file
File.WriteAllLines(path, file)
using(System.StreamWriter file = new StreamWriter()
3 types of collection
- Array
- List
- ArrayList
Array
-fixed size
-generic- everything has to be same sized
List
- can be resized dynamically but arrays cannot.
–generic- everything has to be same sized - can accept null as a valid value for reference types and it
also allows duplicate elements.
ArrayList
-is resizeable
-can have object of diffrent type
-cannot implement a multi-dimensional
array using ArrayList.
Multi-dimensional array
[,] - two dimensioms array- matrix
[,,] - three dimensions array
.Rank- returns a dimension of an array
Jagged Array-
an array inside an array
int[][] jaggedArr= new int[3][]
array with 3 arrays
params keyword-
Dictionaries- generic collections