【问题标题】:C# or VBNET equivalent to scope resolution operator?C# 或 VBNET 等效于范围解析运算符?
【发布时间】:2011-11-22 17:25:09
【问题描述】:

我正在将 php 代码移植到 vbnet(我在 vbnet 方面比 c# 好一点)。在 php 中是范围解析操作符。

这里是位:

$args = phpZenfolio::processArgs( func_get_args() );

c#/vbnet 中的等价物?

整个函数如下,我猜它相当于vbnet中的sub new。

    public function __construct()
{
    $args = phpZenfolio::processArgs( func_get_args() );
    $this->APIVer = ( array_key_exists( 'APIVer', $args ) ) ? $args['APIVer'] : '1.4';
    // Set the Application Name
    if ( ! isset( $args['AppName'] ) ) {
        throw new PhpZenfolioException( 'Application name missing.', -10001 );
    }
    $this->AppName = $args['AppName'];
    // All calls to the API are done via POST using my own constructed httpRequest class
    $this->req = new httpRequest();
    $this->req->setConfig( array( 'adapter' => $this->adapter, 'follow_redirects' => TRUE, 'max_redirects' => 3, 'ssl_verify_peer' => FALSE, 'ssl_verify_host' => FALSE, 'connect_timeout' => 5 ) );
    $this->req->setHeader( array( 'User-Agent' => "{$this->AppName} using phpZenfolio/{$this->version}",
                                  'X-Zenfolio-User-Agent' => "{$this->AppName} using phpZenfolio/{$this->version}",
                                  'Content-Type' => 'application/json' ) );
}

这是进程参数位:

private static function processArgs( $arguments )
 {
    $args = array();
    foreach ( $arguments as $arg ) {
        if ( is_array( $arg ) ) {
            $args = array_merge( $args, $arg );
        } else {
            if ( strpos( $arg, '=' ) !== FALSE ) {
                $exp = explode('=', $arg, 2);
                $args[$exp[0]] = $exp[1];
            } else {
                $args[] = $arg;
            }
        }
    }

    return $args;
  }

【问题讨论】:

    标签: c# php vb.net code-conversion


    【解决方案1】:

    您正在尝试调用static 方法:

    ClassName.MethodName(args);
    

    该方法必须显式声明为static(在Visual Basic 中为Shared)并且不能访问this(在Visual Basic 中为Me)。

    【讨论】:

      【解决方案2】:

      一般来说,作用域解析操作符是点(.)

      http://msdn.microsoft.com/en-us/library/2hxce09y%28v=vs.80%29.aspx

      不过,在某些情况下,别名解析运算符类似于 PHP 或 C++ (::) 中使用的运算符,尤其是在引用全局范围时。

      http://msdn.microsoft.com/en-us/library/htccxtad.aspx

      【讨论】:

        猜你喜欢
        • 2014-01-24
        • 2012-04-20
        • 2011-07-28
        • 2012-05-26
        • 2010-09-09
        • 1970-01-01
        • 2014-10-05
        • 2015-12-18
        • 2016-08-15
        相关资源
        最近更新 更多