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