Закрыть
×
=0) { let js = text.slice(pos1, pos2); + '<\/' + "script" + '>'; arrText.push(js); // next pos1 = pos2; continue; } } } break; } return arrText; } function OpenDialog(parentDiv, urlContent) { parentDiv = document.getElementById('modal-background'); // new !!!!!!! parentDiv.appendChild(document.getElementById('modal-template')); document.getElementById('modal-background').style.display = "flex"; // !!!!! block document.getElementById('modal-template').style.display = "flex"; // !!!!! document.getElementById('modal-body').innerHTML = ""; post_url(urlContent, "", function(text_from_server) { var element = document.getElementById('modal-body'); element.innerHTML = text_from_server; // add scripts var arrJSText = get_scripts(text_from_server); for (var i=0; i
dir.by
Праздники ...
Праздники ...
День города Минска (2-ая суббота сентября) (9 и 10 сентября 2023)
Концерты, выставки ...
Концерты, выставки ...
Полина Гагарина|||г. Минск 10 октября 2026
Афишу
Спорт занятия ...
Спорт занятия ...
Занятия в тренажерном зале
Спорт занятие
Компьютер, программы...
Компьютер, программы...
Объявления ...
Объявления ...
Комплектующие для натяжных потолков
Объявление
Новости ...
Новости ...
Форум ...
Форум ...
обсуждение...
Поиск
Концерты
Спорт
Форум
Компьютер
Компьютер, программы
→
C# (programming language)
In the application C# we call functions from Windows dll (C++ WinAPI). Attribute [DllImport("user32.dll")]
посмотрели
30789
раз
обновлено: 21 June 2023
CLR
(
Common Language Runtime
) is a common language runtime.
Program code that runs under
CLR
is called managed code
(managed code)
.
Code that runs outside of the
CLR
runtime is called unmanaged code
(unmanaged code)
.
Examples of unmanaged code are
Win32 API
functions,
COM
components, and
ActiveX
interfaces.
Despite the large number of
.NET Framework
classes that contain many methods, the programmer still sometimes has to resort to unmanaged code.
It must be noted that the number of calls to unmanaged code decreases with the release of each new version
.NET Framework
.
Microsoft
hopes that there will come a time when all code can be made manageable and secure. But for now, the reality is that we can't do without
Windows API
function calls.
Example
(call function Windows WinAPI)
C#
Creating a new C# console application ...
and write the code
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
// Include the DllImport attribute
using
System.Runtime.InteropServices;
namespace
ConsoleApplication1
{
class
Program
{
// Import the library
user32.dll
(contains
WinAPI
function
MessageBox
)
[
DllImport
(
"user32.dll"
)]
public
static
extern
int
MessageBox(IntPtr hWnd, String text, String caption,
int
options);
// declare the method to
C#
static
void
Main(
string
[] args)
{
// Call
MessageBox
(the function
Windows WinAPI
will be called)
MessageBox(IntPtr.Zero,
"Hello!"
,
"My Message"
, 0);
}
}
}
Example result
Description
Managed code
.NET Framework
can call an unmanaged function from the file
dll
(function
Windows API
) using a special mechanism
Platform Invoke
(abbr.
P/Invoke
).
In order to access any unmanaged library
DLL
, you must convert
.NET
objects into sets of
struct
,
char*
and function pointers, as required by the
C
language.
As programmers would say in their jargon, you need to marshal parameters.
You can read about C# marshaling in the documentation ...
To call a
DLL-
function from
C#
, it must first be declared.
To do this, use the
DllImport
attribute
Sometimes in the examples you can also find this method (long and inconvenient):
[System.Runtime.InteropServices.DllImport("User32.Dll")]
this is not for everyone.
The
DllImport
attribute tells the compiler where the entry point is, which allows the function to be called from the right place.
You should always use the
IntPtr
type for
HWND
,
HMENU
, and any other specifiers.
For
LPCTSTR
, use
String
, and interop services (
interop services
) will automatically marshally
System.String
to
LPCTSTR
before passing to
Windows
. The compiler looks for the above function
SetWindowText
in the file
User32.dll
and automatically converts your string to
LPTSTR (TCHAR*)
before calling it.
Each type in
C#
has its own type to be used in marshaling by default
(default marshaling type)
. For strings, this is
LPTSTR
.
C#
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
// Include the
DllImport
attribute
using
System.Runtime.InteropServices;
namespace
ConsoleApplication1
{
class
Program
{
// Import the library
user32.dll
(contains
WinAPI
function
MessageBox
)
[
DllImport
(
"user32.dll"
)]
public
static
extern
void
SetWindowText(IntPtr hwnd, String lpString);
static
void
Main(
string
[] args)
{
// Call
MessageBox
(the function
Windows WinAPI
will be called)
SetWindowText(IntPtr.Zero,
"Hello!"
);
}
}
}
Calling functions Windows API that have an output string parameter char*
Suppose we need to call the function
GetWindowText
, which has a string output parameter char*. By default,
LPTSTR
is used for strings, but if we use
System.String
, as mentioned above, nothing will happen, since the
System.String
class does not allow you to modify the string. You need to use the
StringBuilder
class, which allows you to modify strings.
C#
// for
StringBuilder
using
System.Text;
[
DllImport
(
"user32.dll"
)]
public
static
extern
int
GetWindowText(IntPtr hwnd, StringBuilder buf,
int
nMaxCount);
The type used for marshashling
StringBuilder
by default is also
LPTSTR
, but now
GetWindowText
can modify your string itself:
C#
StringBuilder sTitleBar =
new
StringBuilder(255);
GetWindowText(this.Handle, sTitleBar, sTitleBar.Capacity);
MessageBox.Show(sTitleBar.ToString());
Thus, the answer to the question of how to call a function that has an output string parameter is to use the
StringBuilder
class.
To change the default marshaling type
For example, we want to call the function
GetClassName
, which takes the parameter
LPSTR (char*)
even in
Unicode-версиях.
If you pass a string, the common language runtime (
CLR
) converts it to the
TCHAR
series. However, you can use the
MarshalAs
attribute to override what is suggested by default:
C#
[
DllImport
(
"user32.dll"
)]
public
static
extern
int
GetClassName(IntPtr hwnd, [MarshalAs(UnmanagedType.LPStr)] StringBuilder buf,
int
nMaxCount);
Now, when you call
GetClassName
,
.NET
will pass your string as
ANSI
characters instead of "wide characters".
Calling functions that require struct
Take, for example, the
GetWindowRect
function, which writes the screen coordinates of a window to the
RECT
structure. To call the function
GetWindowRect
and pass it the structure
RECT
, you need to use the type
struct
in combination with the attribute
StructLayout
C#
[StructLayout(LayoutKind.Sequential)]
public
struct
RECT
{
public
int
left;
public
int
top;
public
int
right;
public
int
bottom;
}
[
DllImport
(
"user32.dll"
)]
public
static
extern
int
GetWindowRect(IntPtr hwnd, ref RECT rc);
It is important to use
C# ref
so that
CLR
passes a parameter of type
RECT
as a reference. In this case, the function will be able to modify your object, rather than its unnamed copy in the stack.
After such a function declaration, you can call it in the code:
C#
int
w, h;
RECT rc =
new
RECT();
GetWindowRect
(this.Handle, ref rc);
w = rc.right - rc.left;
h = rc.bottom - rc.top;
MessageBox.Show(
"Mold width: "
+ w +
"\n\rMold height: "
+ h);
Note that
ref
is used in both the declaration and the function call. The default type used for marshaling types
struct
is
LPStruct
by default, so there is no need for the
MarshalAs
attribute. But if you want to use
RECT
as a class rather than
struct
, you need to implement a wrapper:
C#
// If
RECT
is a class, not a structure (
struct
)
[
DllImport
(
"user32.dll"
)]
public
static
extern
int
GetWindowRect
(IntPtr hwnd, [MarshalAs(UnmanagedType.LPStruct)] RECT rc);
Working with callback functions in C#
To use functions written in
C#
as
Windows
callback functions, you need to use:
delegate
C#
delegate
bool
EnumWindowsCB(
int
hwnd,
int
lparam);
After declaring your delegate type, you can write a wrapper for the
Windows API
function:
C#
[
DllImport
(
"user32"
)]
public
static
extern
int
EnumWindows
(EnumWindowsCB cb,
int
lparam);
Since the line with
delegate
simply declares the delegate type
(delegate type)
, the delegate itself must be provided in the class:
C#
public
static
bool
MyEWP(
int
hwnd,
int
lparam)
{
// Doing something here
return
true;
}
And then we transfer:
C#
EnumWindowsCB cb =
new
EnumWindowsCB(MyEWP);
Win32.EnumWindows(cb, 0);
Astute readers will notice that I kept silent about the problem with
lparam
.
In
C++
language, if
LPARAM
is given in
EnumWindows
,
Windows
will notify your callback function with this
LPARAM
. Usually,
lparam
is a pointer to some structure or class that contains the context information you need to perform your operations.
But remember:
In
.NET
the word
pointer
cannot be pronounced! So what to do? You can declare your
lparam
as
IntPtr
and use
GCHandle
as its wrapper:
C#
//
lparam
— this is type
IntPtr
delegate
bool
EnumWindowsCB(
int
hwnd, IntPtr lparam);
// Place the object in the shell
GCHandle
MyClass obj =
new
MyClass();
GCHandle gch = GCHandle.Alloc(obj);
EnumWindowsCB cb =
new
EnumWindowsCB(MyEWP);
Win32.EnumWindows(cb, (IntPtr)gch);
gch.Free();
Don't forget to call
Free
when you're done!
Sometimes in
C#
you have to free the memory yourself. To access
pointer lparam
inside an enumerator, use
GCHandle.Target
C#
public
static
bool
MyEWP(
int
hwnd, IntPtr param)
{
GCHandle gch = (GCHandle)param;
MyClass c = (MyClass)gch.Target;
// ... Use
return
true;
}
Below is a class I wrote that encapsulates
EnumWindows
in an array.
Instead of fiddling with all those delegates and callbacks, you write:
C#
WindowArray wins =
new
WindowArray();
foreach
(
int
hwnd
in
wins)
{
// doing something here...
}
C#
File
ListWin.cs
//
WinArray
generates
ArrayList
top-level windows using
EnumWindows
using
System;
using
System.Collections;
using
System.Runtime.InteropServices;
namespace
WinArray
{
public
class
WindowArray
: ArrayList
{
private
delegate
bool
EnumWindowsCB(
int
hwnd, IntPtr param);
// Declared as
private
because only I need it
[
DllImport
(
"user32"
)]
private
static
extern
int
EnumWindows(EnumWindowsCB cb,
IntPtr param);
private
static
bool
MyEnumWindowsCB(
int
hwnd, IntPtr param)
{
GCHandle gch = (GCHandle)param;
WindowArray itw = (WindowArray)gch.Target;
itw.Add(hwnd);
return
true;
}
// This is the only public (
public
) method.
// Only you need to call him.
public
WindowArray()
{
GCHandle gch = GCHandle.Alloc(this);
EnumWindowsCB ewcb =
new
EnumWindowsCB(MyEnumWindowsCB);
EnumWindows(ewcb, (IntPtr)gch);
gch.Free();
}
}
}
A small program
ListWin
(Appendix
ListWin.cs
), for enumerating top-level windows, allows you to view lists of
HWND
, class names, titles, and window rectangles using
RECT
or
Rectangle
.
← Previous topic
Marshaling (marshalling) in C#. Type Conversion Between Managed Code (managed code) and Unmanaged Code (unmanaged code)
Next topic →
In a C# application, call functions from my dll (C++). Attribute [DllImport("My.dll", CallingConvention = CallingConvention.Cdecl)]
Your feedback ...
1
Comments
guest
12 October 2021 20:01
Какая же тут годная информация. Без воды и пр :) Отличный сайт, автору респект :)
answer
Your Name
Your comment
(www links can only be added by a logged-in user)
+ Picture
Объявления
Объявления
•
Download and install Microsoft Visual Studio
•
Download and install Visual Studio 2026 (for learning C#, writing programs): WPF, ASP.NET, ASP.NET Core, UWP, Maui, Xamarin, Unity, MonoGame)
•
Download and install Visual Studio 2022 (for learning C#, writing programs): WPF, ASP.NET, ASP.NET Core, UWP, Maui, Xamarin, Unity, MonoGame)
•
Download and install Visual Studio 2019 (for learning C#, writing programs: WPF, ASP.NET, ASP.NET Core, Xamarin, Unity, MonoGame)
•
Download and install Visual Studio 2017 (to learn C#, writing programs: WPF, ASP.NET, ASP.NET Core, Xamarin, Unity, MonoGame)
New app for learning C#
•
Creating a new console application to learn C#
Debugging Code
•
Debug.Assert(false) Debugging Code in C#
•
For debugging, option "Common Language Runtime Exceptions" see exceptions when a program is running C#
•
Attribute [Obsolete("My method is outdated. Do not use", false)] Warning when compiling code in the C#
Data Types C#
•
C# data types: number (bool, char, byte, int, long, float, double, decimal), text (string), enumeration (enum), class (class), structure (struct)
•
Structure Boolean in the C# it is a flag with values true or false (bool) and methods for conversion bool
•
Structure Int32 in the C# it is a signed integer (int) and methods for conversion int
•
Structure Single in the C# this is a floating-point number (float) and methods for conversion float
•
var ... Variable of any type in the C#. Example: var str = "Hello!";
•
Type dynamic in the C#
•
Default values in the C#
Storing objects in memory. Removing Objects from Memory
•
Reference types and value types in the C#
•
Stack (stack) - memory for method parameters and local variables in the C#
•
Heap - dynamic memory available at run time in the C#
•
Interface IDisposable. Write code to properly release unmanaged resources in the destructor and in the interface IDisposable in the C#
•
Memory. Garbage collector (garbage collector). Automatic memory freeing in the C#
C# type conversion
•
C# converting a string to a number (string → short, int, long, ushort, uint, ulong, float, double, decimal) | Use Culture (system settings)
•
C# converting a number to a string (int, double, short, ... → string) with the required accuracy
Text in C# (type string and class String)
•
Algorithm for intersecting rectangles
•
What is text in the C# ? Type string and class String. Methods for working with text.
•
Length (string length in C#). Example: string str1 = "Hello"; int v1 = str1.Length;
•
CompareTo (compares case-sensitive text in C#). Example: bool bIsSame = str1.CompareTo(str2)==0;
•
ToLower (converts text to lowercase in C#). Example: string str1 = "HELLO World!"; string str2 = str1.ToLower();
•
ToUpper (converts text to uppercase in C#). Example: string str1 = "Hello World!"; string str2 = str1.ToUpper();
•
Split (split the string into words in C#). Example: string[] arrWords = strText.Split(" ");
•
StartsWith (checks the beginning of the text with the specified case-sensitive text in C#). Example: bool bStart = str1.StartsWith(str2);
•
Contains (checks whether the text specified is case-sensitive or not in case-sensitive C#). Example: bool bFound = str1.Contains(str2);
•
IndexOf (searches for a case-sensitive string and returns the position in C#). Example: int pos = str1.IndexOf(str2);
•
Substring (returns part of the text from the specified position and length in the C#). Example: string str1 = "Hello World!"; string str2 = str1.Substring(2, 5);
•
IsNullOrEmpty (checks the text for blank or for null in the C#). Example: string name = "Hello World!"; bool bFlag = String.IsNullOrEmpty(name);
•
IsNullOrWhiteSpace (validates text on null or on text with spaces in the C#). Example: string name = " "; bool bFlag = String.IsNullOrWhiteSpace(name);
•
[] (returns a character from the specified position in the C#). Example: char symbol = str[1];
•
Format (text formatting, strings in the C#). Example: string strNew = String.Format("Hello {0}, {1}", name, year);
•
+ (add lines and text in the C#). Example: string str = str1 + str2 + " people!";
•
$ (string interpolation in the C#). Example: string result = $"Hello {a} + {b} = {a + b}";
•
Symbol @ before the beginning of the line in the C#. Example: string str1 = @"aaa";
•
Use @ and $ together (C# string interpolation)
DateTime in C#
•
What is DateTime in C# ? Convert to a string with the format
Enumerations in C # (enum)
•
What is enumeration? (enum) in the C# ?
•
How to convert text to enum in C#
•
How to enumerate all elements in enum in C#
null
•
null value for simple types. Use ? or Nullable in the C#
•
Operator ?? (null-union) in the C#
try-catch
•
Exception handling in C#. Operator try catch finally
Classes in C# (class)
•
What is a class? in the C#?
•
Class Access Modifiers in the C#. Access modifiers for methods, properties, fields in the C#
•
"partial class" in the C#. Description of the class in different files
[bgcolor=#F5F9DB]Constructors for a class[/bgcolor]
•
Class Constructor in the C#
•
Initializing a Class Object (set values for fields) in the C#
•
To call the constructor at the base class in the C#
•
Static constructor in class C#
•
"base" To call a method from the base class. To call a variable from the base class. To call the constructor from the base class. C#
•
"this" To set or get a value from a class field. To call the constructor from the class. C#
[bgcolor=#F5F9DB]Class Destructors[/bgcolor]
•
Class Destructor in the C#
•
Destructors in classrooms (how basic destructors are called) C#
[bgcolor=#F5F9DB]Inheritance[/bgcolor]
•
What is class inheritance in C# ?
[bgcolor=#F5F9DB]Inheritance using new[/bgcolor]
•
Use new for the interface method. Inheriting an interface from an interface with the same method
•
Use new for the class method. Inheriting a class from a class in C#.
[bgcolor=#F5F9DB]Inheritance using sealed[/bgcolor]
•
sealed class. Prohibition to inherit in the C#
•
Inheriting a class from a class in C#. We use words virtual, override, sealed for class methods
[bgcolor=#F5F9DB]Abstract class[/bgcolor]
•
What is an abstract class? in the C# ? Abstract methods, properties, indexes.
•
Inheritance from a class abstract in the C#. Use abstract and override for class methods
[bgcolor=#F5F9DB]Constants and readonly [E_M_P_T_Y] fields in the classroom[/bgcolor]
•
Constants in the classroom C#
•
readonly . For a class field. This field is read-only in C#
[bgcolor=#F5F9DB]Properties get and set in the classroom C# (accessors)[/bgcolor]
•
get set Properties in a class C#
•
Inheritance (virtual, override) for get and set accessors in C#
[bgcolor=#F5F9DB]Operators, indexers in C#[/bgcolor]
•
Operators in a C# class. Operator overload: > < ++ + true false
•
Indexers in Class C#
[bgcolor=#F5F9DB]Nested types in C#[/bgcolor]
•
Nested class, structure in C#
[bgcolor=#F5F9DB]Parameters in the C#[/bgcolor] class method
•
ref and out (return parameters by reference in the C# method). Example: public void AddValue(ref int value)
•
Default parameters (optional parameters) in a C# method. Example: public int CalculateSum(int a, int b, int c=7)
•
C# named parameters. Example: public void CalculateSum(a:7, b:3);
[bgcolor=#F5F9DB]Generic methods, generic classes in C# (templates)[/bgcolor]
•
A method with generic parameters in C# (templates). Example: public double Sum<T1, T2>(T1 value1, T2 value2) { ... }
•
A generic (typed) class in C# (templates). Example of a class Book<T> { ... }
•
where Type constraint in a generic (typed) class in C# (templates). Example of class Dog<T> where T : Cat
[bgcolor=#F5F9DB]Converting a class object from one type to another[/bgcolor]
•
explicit is an explicit conversion operator in the C class#
•
implicit is an implicit conversion operator in class C#
•
Converting a class object from one type to another in C#. Use try( ) is as
•
Converting a class object from one type to another in C#. Using pattern matching is switch
[bgcolor=#F5F9DB]Class object in C#[/bgcolor]
•
? conditional null operator in C#
•
The class object contains a reference in C#
•
How do you copy objects in C# to copy class data instead of a reference?
[bgcolor=#F5F9DB]Static constructor and static properties and methods[/bgcolor]
•
Static constructor in class C#
•
Static methods, properties, members in class C#
[bgcolor=#F5F9DB]Additional class features in C#[/bgcolor]
•
The extension method in C# (this in the first parameter of the method). Example: static public void AddValues(this List<int> myList, int value1, int value2)
[bgcolor=#F5F9DB]Class naming conventions in C#[/bgcolor]
•
What letters, lowercase or uppercase, to call classes, methods, properties... in C#
•
Is it correct to create a separate .cs file for each class in C#? Or write C# classes in a single .cs file?
Static Class
•
Static Class in C#
Anonymous Class
•
An object with an anonymous (missing) type in C#. Example: var book = new { BookName = "Lord of the Rings", Price = 100 };
Interfaces
•
What is interface in C#?
•
Inheriting the interface from the interface in C#
•
Inheriting a class from an interface class in C#. Using override and virtual for class methods
•
Generalized (typed) interface in C# (templates). Example interface IUser<T> { ... }
Struct structure
•
What is a structure in C#?
•
Structure access modifiers in C#. Access Modifiers for Methods, Properties, Struct Fields in C#
•
Initializing a Structure Object (Setting Values for Fields) in C#
•
How to change the value in an array of structures or in a collection of structures (List) in C#
•
Nested structure in C#
[bgcolor=#F5F9DB]Converting a struct object from one type to another[/bgcolor]
•
implicit is an implicit struct-to-C conversion operator#
•
explicit is an explicit struct-to-C conversion operator#
Lazy class loading in C#
•
Lazy Object Creation in Memory (class Lazy in C#)
Tuples
•
Tuples in C#
Dynamic objects with any properties
•
DynamicObject and ExpandoObject in C#
Arrays
•
What are arrays? array in C#
•
Initializing an Array (Populating the Array Elements) in C#
•
params passing any number of parameters to a method in C#
•
Array class C#
Collection
•
What are collections in C#?
•
What are non-generic collections in C#? ArrayList, Stack, Queue, Hashtable, SortedList, BitArray classes
•
What are generic (typed) collections in C#? The classes are List<T>, SortedList<T>, Stack<T>, Dictionary<TKey, TValue>, LinkedList<T>, Queue<T>, HashSet<T>, SortedSet<T>, ConcurrentDictionary<TKey, TValue>, SortedDictionary<TKey, TValue>
Non-generic collection classes (different types of items are stored in the same collection)
•
IEnumerable interface. The most basic interface for collections in C#
•
Interfaces: ICollection, IList, IDictionary. The basis for collections in C#
ArrayList class (collection in C#)
•
What is ArrayList in C#?
SortedList class (collection in C#)
•
What is SortedList in C#?
Stack class (collection in C#)
•
What is Stack in C# ?
Queue class (collection in C#)
•
What is Queue in C# ?
Hashtable class (collection in C#)
•
What is a Hashtable in C# ?
BitArray class (collection in C#)
•
What is BitArray in C#?
Generic, typed collection classes in C# (elements of the same type are stored in the same collection)
•
IEnumerable interface<T>. The most basic interface for typed collections in C#
•
Interfaces: ICollection<T>, IList<T>, ISet<T>, IDictionary<TKey, TValue>. Basis for typed collections in C#
List class<T> (typed collection in C#)
•
What is List<T> in C#?
•
Initializing the Collection List in curly brackets in the C#
•
for, foreach (go through all the items in the List<T>) in C#
•
Find (looking for an item by criterion in the List<T>) in C#
•
FindAll (looking for a list of items by criterion in the List<T>) in C#
•
ForEach (for each List element an<T> action is performed) in C#
LinkedList class<T> (typed collection in C#)
•
What is LinkedList<T> in C# ?
SortedList<TKey, TValue> class (typed collection in C#)
•
What is SortedList<TKey, TValue> in C# ?
Stack class<T> (typed collection in C#)
•
What is Stack<T> in C# ?
Queue class<T> (typed collection in C#)
•
What is Queue<T> in C# ?
HashSet class<T> (typed collection in C#)
•
What is a HashSet<T> in C# ?
•
How HashSet works<T> in C#
SortedSet class<T> (typed collection in C#)
•
What is a SortedSet<T> in C#?
ObservableCollection class<T> (typed collection in C#)
•
What is ObservableCollection<T> in C#?
Dictionary<TKey, TValue> class (typed collection in C#)
•
What is Dictionary<TKey, TValue> in C# ?
•
Initializing Elements in the Dictionary<TKey, TValue> Constructor in C#
•
How Dictionary<TKey, TValue> works in C#
•
How to convert IEnumerable to → Dictionary in C#<TKey, TValue> . Using the ToDictionary method
SortedDictionary<TKey, TValue> class (typed collection in C#)
•
What is SortedDictionary<TKey, TValue> in C# ?
ConcurrentDictionary<TKey, TValue> class (typed collection in C#)
•
What is ConcurrentDictionary<TKey, TValue> in C# ?
•
AddOrUpdate (add or update a value by key in ConcurrentDictionary<TKey, TValue>) in C#
Asymptotic complexity for adding, removing, taking an item in collections
•
Asymptotic complexity for adding, removing, taking an element in collections C# (List, SortedList, Stack, Dictionary, LinkedList, Queue, HashSet, SortedSet, ConcurrentDictionary, SortedDictionary)
Sorting Elements in the [] Array and List <T>Collection
•
Sorting elements in the [] array and List collection<T> in C#. IComparable interface
•
Sorting elements in the [] array and List collection<T> in C#. IComparer interface
My implementation of IEnumerator, IEnumerable, and iterators
•
Example: My implementation of the IEnumerable and IEnumerator interfaces in C#
•
Iterators and yield in C#. Examples of IEnumerable implementation with yield
Extension Methods for IEnumerable<T> (Search, Replace, Value Sampling) in C#
•
Methods for finding, replacing, and fetching values in IEnumerable<T>. Extension methods for IEnumerable<T> in C#
•
Any (IEnumerable extension method<T>) in C#
•
Select (IEnumerable extension method<T>) in C#
•
GroupBy (extension method IEnumerable<T>) in the C#
•
GroupJoin (extension method IEnumerable<T>) in the C#
Sorting, filtering in LINQ (Language-Integrated Query)
•
What is LINQ in C#?
•
Sorting, filtering list items using LINQ in C#
•
Books for learning LINQ in C#
Pointers
•
Pointers in C#. Operator unsafe
•
Pointers to structs, class fields, arrays in C#. Operators unsafe, stackalloc, fixed
Working with files
•
Open the file, read the text from the file and break it down by words. C#
•
Create a text file, write the text to a C file#
•
Create an HTML file, write tabular data in an HTML file | C#
•
Create a binary file, write bytes to file C#
•
Partial upload of a file from FTP to C#
•
Class Path. Combine method - merges the strings into the full path of the file. And other methods of the Path class | C#
Serialization
•
What is object serialization in C#? [Serializable] attribute
•
Serializing a C# object into a binary file. BinaryFormatter class. [Serializable] attribute
•
Serializing a C# object into an XML file. XmlSerializer class. [Serializable] attribute
•
Serialization of a C# object into a JSON file. DataContractJsonSerializer class. [Serializable] attribute
•
Serializing a C# object into a SOAP file. SoapFormatter class. [Serializable] attribute
Namespaces
•
Namespace using in C#
Delegate
•
Delegate in C#
•
Add method(s) in a C# delegate. Unification of delegates. Removing a Method from a Delegate
•
Delegate as a parameter in method C#
•
Unnamed, anonymous method in C# (method described in place of parameter, delegate)
Universal Delegates
•
Generic, generic delegates in C# (templates)
•
Action, Predicate, and Func Universal Delegates in C#
Events
•
Events in C#
Lyamda
•
Lamda (example) in C#
Regular expressions
Regular Expressions in C#
•
Breaking the text into words (regular expressions in c#)
•
Put * instead of the last name after the first letter (regular expressions in c#)
•
Breaking the text into words (regular expressions in c#)
Process, process modules
•
Process in C# (Process class)
•
Process modules in C# (ProcessModule class)
Threads, multithreading
•
Threads in C# (Thread class)
•
Thread Pool in C#
•
What"s the difference between background and foreground in C#?
•
Synchronizing Threads in C#
Parallel Library Task (TPL)
•
Parallel Library Task (TPL). Parallel Task Library in C#
•
The Parallel class uses the Invoke method to execute the for and foreach (on different CPU cores) methods in parallel in C#
•
PLINQ parallelizes LINQ queries to run on different processor cores in C#
Asynchronous methods (async and await)
•
class Task in C#
•
Asynchronous programming in C# (async, await how to formalize)
•
Asynchronous programming in C# (using async, await, and Task as an example)
•
Asynchronous Programming in C# (Theory)
Application domains
•
What are Application Domains in C# ? (AppDomain class)
•
Example "Application domain information" (current domain name, list assemblies) in C#
•
Example "Let"s create the 2nd application domain. Write the class in the 1st domain and use it in the 2nd domain. MarshalByRefObject in C#
•
Example "Load the 2nd domain of the application from a file, run the calculations, unload the 2nd domain from memory" to C#
Attributes
•
Attributes for Class, Method, Property in C#
•
Attribute [Conditional("AAA")] . For compilation, ignore a method or property unless a conditional compilation symbol is defined in C#
•
Attribute [Obsolete("My method is outdated. Do not use", false)] Warning when compiling code in the C#
•
The [Display(Name="Sleep at night")] attribute. To store some text attached to a variable | C#
•
The attribute [Required(ErrorMessage = "Please enter a name")] is described for a property in the C# class and requires the property to be populated if the ErrorMessage error in the MVC ASP.NET is not filled in the screen
•
The attribute [Remote("IsValidAuthor", "Home", ErrorMessage = "Enter correct author of book")] is described for a property in a C# class and checks that property for correctness on the server via the IsValidAuthor method in conroller Home, if the method returns false, then there will be an ErrorMessage error on the screen in the MVC ASP.NET
Reflection in C#
•
Nameof operator in C# (class name, method name, variable name)
•
What is reflection in C#? Type Class
•
Creating a class object and calling the constructor with parameters using reflection in C#
•
How to get attribute information for a method from a class. Using reflection | C#
•
How to get attribute information for a property of a class. Using reflection | C#
•
How to change the set property in a class if private using reflection | C#
Preprocessor directives (if on compilation)
•
#define #undef #if #elif #else #endif preprocessor directives in C#
•
How do I define #define for all files (for the entire project) in C#?
What is the CLR assembly and runtime?
•
Assembly (Assembly) in C#. Compilation. Intermediate code IL (Intermediate Language). Metadata.
•
How to include a C# assembly in a project?
•
Utility ildasm.exe. Converts an assembly (C# exe, dll file) to an intermediate language (IL). This utility is easy to learn
•
The runtime CLR (Common Language Runtime) in C# . JIT (Just-In-Time) compiler.
Creating and connecting our build
•
Creating our C# build (regular build)
•
Connecting our C# build (regular build)
▷
•
Creating our C# assembly (split assembly)
•
Connecting our C# assembly (split assembly)
Database in Console Application C#
•
Entity Framework in a C# console application. Using Code First (we write c# code, and the tables in the database are created by ourselves)
•
Read the image from the database and save it to a file | ADO.NET, C#, console application
DI Dependency Injection in C#
•
Dependency injection in C# | Dependency Injection (DI)
•
Ninject (IoC container) dependency management in C#
•
Autofac (IoC container) dependency management in C#
Convenient Visual Studio utilities
•
View Class Diagram in C#
exe to C# code
•
"dotPeek" application for decompile (disassemble) exe to c# source code
In a C# application, call the C++ functions
•
What are managed code (managed code) and unmanaged code (unmanaged code)? | C# and C++
•
Marshaling (marshalling) in C#. Type Conversion Between Managed Code (managed code) and Unmanaged Code (unmanaged code)
•
In the application C# we call functions from Windows dll (C++ WinAPI). Attribute [DllImport("user32.dll")]
•
In a C# application, call functions from my dll (C++). Attribute [DllImport("My.dll", CallingConvention = CallingConvention.Cdecl)]
Additional topics, questions
•
You don"t create a new project in Visual Studio 2019. Object reference not set to instance of an object"
•
C# compilation error: error CS1106: Extension method must be defined in a non-generic static class
•
C# compilation error: error CS0246: The type or namespace name "Point" could not be found (are you missing a using directive or an assembly reference?)
•
Why can"t the Dictionary.TryGetValue method find a value by key in C#?
•
Object-oriented programming (OOP). OOP Principles: Abstraction, Encapsulation, Inheritance, Polymorphism
•
What letters in C# (uppercase or lowercase or uppercase) should we use to name fields, methods in a class, interfaces, delegates, parameters?
•
Is it correct to create a separate .cs file for each class in C#? Or write C# classes in a single .cs file?
•
Is it better to use a built-in int type or an Integer class (string type or String class) in C#?
•
How do I download and install the version of the .NET Framework I want in Visual Studio?
•
Boxing and unboxing meaningful types in C#
•
Error CS8107 Feature "default literal" is not available in C# 7.0. Please use language version 7.1 or greater
•
Error "unable to connect to web server "iis express" | C# | Visual Studio 2017
•
Uninstall and install NuGet in Visual Studio
•
When opening a project in Visual Studio 2019 error: "project requires "SQL Server 2012 Express LocalDB" which is not installed on this computer"
The checked and unchecked math operators
•
The unchecked math operator in C#
•
The checked math operator in C#
Additional C# classes
•
C# Random class
•
C# Structure Point
•
C# PointF structure
•
C# Size structure
•
C# SizeF structure
•
C# Rectangle Structure
•
C# RectangleF structure
It"s time
•
The amount of time that has elapsed since the system booted (in milliseconds). System.Environment.TickCount in C#
Encryption
•
Let"s encrypt the password and check it | C# console application
Excell
•
Reading an excel file in C# (console application)
WWW Sites to Learn C#
•
Websites to learn C#
Ваши вопросы присылайте по почте:
info@dir.by