共用方式為


auto_gcroot::swap

將物件與另一個 auto_gcroot 交換。

void swap(
   auto_gcroot<_element_type> & _right
);

參數

  • _right
    擁有將被交換的物件之 auto_gcroot。

範例

// msl_auto_gcroot_swap.cpp
// compile with: /clr
#include <msclr\auto_gcroot.h>

using namespace System;
using namespace msclr;

int main() {
   auto_gcroot<String^> s1 = "string one";
   auto_gcroot<String^> s2 = "string two";

   Console::WriteLine( "s1 = '{0}', s2 = '{1}'",
      s1->ToString(), s2->ToString() );
   s1.swap( s2 );
   Console::WriteLine( "s1 = '{0}', s2 = '{1}'",
      s1->ToString(), s2->ToString() );
}
  

需求

標頭檔 <msclr \ auto_gcroot.h>

命名空間 msclr

請參閱

參考

swap 函式 (auto_gcroot)

其他資源

auto_gcroot 成員