1. Structure: In C#, a structure (struct) is a user-defined value type used to encapsulate a set of related data fields. Unlike classes, structures are value types, while classes are reference types. This means that instances of structures are copied when assigned to variables, passed to methods, or passed as function arguments, whereas instances of […]
Tag: delegates
C++ – Implementing events and delegates, signals and slots mechanisms using the standard library
Use the C++ standard library to simply implement event triggering mechanism Event.h /* Author:StubbornHuang Data:2023.1.31 Email:[email protected] */ #ifndef _EVENT_H_ #define _EVENT_H_ #include <functional> #include <map> #include <type_traits> #ifndef EVENT_NO_THREAD_SAFETY #define EVENT_THREAD_SAFETY #endif // !EVENT_NO_THREAD_SAFETY #ifdef EVENT_THREAD_SAFETY #include <atomic> #include <mutex> #endif // EVENT_THREAD_SAFETY #ifdef EVENT_THREAD_SAFETY #define DELEGATE_ID_TYPE std::atomic_uint64_t #else #define DELEGATE_ID_TYPE std::uint64_t #endif // EVENT_THREAD_SAFETY […]
Using various custom delegates in QTableView
QT’s MVC (View/Delegate) model is very powerful and can use various controls to limit table input. Idea: 1: Define delegates for each column: A: The first column is the number column. Use a read-only delegate to make the cells in this column read-only. B: The third column is the ID column. Only 1-12 numbers can […]
Asynchronous calls to delegates and methods
Overview Asynchronous calls are usually used to perform some time-consuming operations, while ensuring that the current main thread can continue to execute after executing the asynchronous call. During asynchronous execution, the system often creates a new thread, but it should be noted that when each asynchronous execution requires the creation of a thread, performance will […]
Jing: Why should delegates be introduced in C#
Introduction: For some friends who are new to C#, they may not have a deep understanding of some basic features in C#. However, this knowledge is also a question that interviewers often ask during interviews, so I think it is necessary to share with some friends who have not been in contact with C# for […]
[C#] Delegates, anonymous methods, Lambda expressions and events
【C#】Delegate, Anonymous Method, Lambda Expression and Event Delegation What is a delegation? Like a class, a delegate is a user-defined type and an abstraction of a method (function). In layman’s terms, a delegate is a representative of a method (function) of a custom type. Declaration delegation //<access modifier> delegate <function return type> <custom delegate name> […]
C# delegates, lambda expressions and events
1. Reference method Delegates are the .NET equivalent of addressing methods. In C++, a function pointer is nothing more than a pointer to a memory location, which is not type safe. We can’t tell what this pointer actually points to, let alone items like parameters and return types. A .NET delegate is completely different; a […]
C# delegates and events, anonymous functions and lamabda expressions
Article directory (1) commission (2) Events (3) Anonymous function (4) lambda expression (5) Closure (1) Delegation The delegate is the container of the function method, which can be understood as the variable type of the function method, which is used to store the transfer function method The essence of delegation is a class, which is […]
Use Kotlin delegates to split more complex ViewModels
Requirement Background In an actual development scenario, the data of a page may be composed of data of multiple businesses. Implemented using the MVVM architecture, storing and processing multiple business data in the ViewModel, and notifying the View layer to refresh the UI. Traditional implementation For example, in the above example, the page consists of […]
QML Deformation Agents (Shape-Shifting Delegates)
When working with linked lists, the mechanism of expanding when the current item is activated is usually used. This operation can be used to dynamically fill the entire screen with the current item to add a new user interface, or to provide more information about the current item in a linked list. In the following […]