14.4 Function members

本文详细介绍了C#中函数成员的概念及分类,包括方法、属性、事件等,并阐述了如何通过重载解析来确定调用哪个函数成员,以及运行时如何实际调用这些成员。
Function members are members that contain executable statements. Function   
                                          
members are always members                                                  
                                          
of types and cannot be members of namespaces. C# defines the following      
                                          
categories of function members:                                             
                                          
?Methods                                                                   
                                          
?Properties                                                                
                                          
?Events                                                                    
                                          
?Indexers                                                                  
                                          
?User-defined operators                                                    
                                          
?Instance constructors                                                     
                                          
?Static constructors                                                       
                                          
?Destructors                                                               
                                          
Except for static constructors and destructors (which cannot be invoked     
                                          
explicitly), the statements contained                                       
                                          
in function members are executed through function member invocations. The   
                                          
actual syntax for writing a                                                 
                                          
function member invocation depends on the particular function member        
                                          
category.                                                                   
                                          
The argument list (?4.4.1) of a function member invocation provides actual 
                                          
values or variable references                                               
                                          
for the parameters of the function member.                                  
                                          
Invocations of methods, indexers, operators, and instance constructors      
                                          
employ overload resolution to                                               
                                          
determine which of a candidate set of function members to invoke. This      
                                          
process is described in ?4.4.2.                                            
                                          
Once a particular function member has been identified at compile-time,      
                                          
possibly through overload                                                   
                                          
resolution, the actual run-time process of invoking the function member is  
                                          
described in ?4.4.3.                                                       
                                          
[Note: The following table summarizes the processing that takes place in    
                                          
constructs involving the six                                                
                                          
categories of function members that can be explicitly invoked. In the       
                                          
table, e, x, y, and value indicate                                          
                                          
expressions classified as variables or values, T indicates an expression    
                                          
classified as a type, F is the simple                                       
                                          
name of a method, and P is the simple name of a property.                   
                                          

Construct   Example     Description
-------------------------------------------------------------------------
Method      F(x, y)     Overload resolution is applied to select
invocation          the best method F in the containing class
                or struct. The method is invoked with the
                argument list (x, y). If the method is not
                static, the instance expression is this.
-------------------------------------------------------------------------   


   
        T.F(x, y)   Overload resolution is applied to select
                the best method F in the class or struct
                T. A compile-time error occurs if the
                method is not static. The method is invoked
                with the argument list (x, y).
-------------------------------------------------------------------------   
   
        e.F(x, y)   Overload resolution is applied to select the
                best method F in the class, struct, or
                interface given by the type of e. A
                compile-time error occurs if the method is
                static. The method is invoked with the
                instance expression e and the argument
                list (x, y).
-------------------------------------------------------------------------   
   
Property    P       The get accessor of the property P in the
access              containing class or struct is invoked. A
                compile-time error occurs if P is writeonly.
                If P is not static, the instance expression
                is this.
-------------------------------------------------------------------------   
   
        P = value   The set accessor of the property P in the
                containing class or struct is invoked with
                the argument list (value). A compiletime
                error occurs if P is read-only. If P is not
                static, the instance expression is this.
-------------------------------------------------------------------------   
   
        T.P     The get accessor of the property P in the
                class or struct T is invoked. A compile-time
                error occurs if P is not static or if P is
                write-only.
-------------------------------------------------------------------------   
   
        T.P = value The set accessor of the property P in the
                class or struct T is invoked with the
                argument list (value). A compile-time error
                occurs if P is not static or if P is
                read-only.
-------------------------------------------------------------------------   
   
        e.P     The get accessor of the property P in the
                class, struct, or interface given by the
                type of e is invoked with the instance
                expression e. A compile-time error occurs
                if P is static or if P is write-only.
--------------------------------------------------------------------------  
   
        e.P = value The set accessor of the property P in the
                class, struct, or interface given by the
                type of e is invoked with the instance
                expression e and the argument list (value).
                A compile-time error occurs if P is static
                or if P is read-only.
--------------------------------------------------------------------------  
   
Event access    E += value  The add accessor of the event E in the
                containing class or struct is invoked. If
                E is not static, the instance expression
                is this.
-------------------------------------------------------------------------   
   
        E -= value  The remove accessor of the event E in the
                containing class or struct is invoked. If
                E is not static, the instance expression
                is this.
------------------------------------------------------------------------    
   
        T.E += value    The add accessor of the event E in the
                class or struct T is invoked. A
                compile-time error occurs if E is not
                static.
------------------------------------------------------------------------    
   
        T.E -= value    The remove accessor of the event E in the
                class or struct T is invoked. A
                compile-time error occurs if E is not
                static.
------------------------------------------------------------------------    
   
        e.E += value    The add accessor of the event E in the
                class, struct, or interface given by the
                type of e is invoked with the instance
                expression e. A compile-time error occurs
                if E is static.
------------------------------------------------------------------------    
   
        e.E -= value    The remove accessor of the event E in the
                class, struct, or interface given by the
                type of e is invoked with the instance
                expression e. A compile-time error occurs
                if E is static.
------------------------------------------------------------------------    
   
Indexer     e[x, y]     Overload resolution is applied to select 
access              the best indexer in the class, struct, or
                interface given by the type of e. The get


                accessor of the indexer is invoked with the
                instance expression e and the argument list
                (x, y). A compile-time error occurs if the
                indexer is write-only.
------------------------------------------------------------------------   
        e[x, y] = value Overload resolution is applied to select
                the best indexer in the class, struct, or
                interface given by the type of e. The set
                accessor of the indexer is invoked with
                the instance expression e and the argument
                list (x, y, value). A compile-time error
                occurs if the indexer is read-only.
------------------------------------------------------------------------    
   
Operator    -x      Overload resolution is applied to select 
invocation          the best unary operator in the class or
                struct given by the type of x. The
                selected operator is invoked with the
                argument list (x). 
------------------------------------------------------------------------   
        x + y       Overload resolution is applied to select
                the best binary operator in the classes
                or structs given by the types of x and y.
                The selected operator is invoked with the
                argument list (x, y).  
------------------------------------------------------------------------    
    
Instance    new T(x, y) Overload resolution is applied to select
constructor         the best instance constructor in the class
invocation          or struct T. The instance constructor is
                invoked with the argument list (x, y).               
                           
【电动汽车充电站有序充电调度的分散式优化】基于蒙特卡诺和拉格朗日的电动汽车优化调度(分时电价调度)(Matlab代码实现)内容概要:本文介绍了基于蒙特卡洛和拉格朗日方法的电动汽车充电站有序充电调度优化方案,重点在于采用分散式优化策略应对分时电价机制下的充电需求管理。通过构建数学模型,结合不确定性因素如用户充电行为和电网负荷波动,利用蒙特卡洛模拟生成大量场景,并运用拉格朗日松弛法对复杂问题进行分解求解,从而实现全局最优或近似最优的充电调度计划。该方法有效降低了电网峰值负荷压力,提升了充电站运营效率与经济效益,同时兼顾用户充电便利性。 适合人群:具备一定电力系统、优化算法和Matlab编程基础的高校研究生、科研人员及从事智能电网、电动汽车相关领域的工程技术人员。 使用场景及目标:①应用于电动汽车充电站的日常运营管理,优化充电负荷分布;②服务于城市智能交通系统规划,提升电网与交通系统的协同水平;③作为学术研究案例,用于验证分散式优化算法在复杂能源系统中的有效性。 阅读建议:建议读者结合Matlab代码实现部分,深入理解蒙特卡洛模拟与拉格朗日松弛法的具体实施步骤,重点关注场景生成、约束处理与迭代收敛过程,以便在实际项目中灵活应用与改进。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值