当前位置: 首页 > news >正文

威海北京网站建设网站永久空间

威海北京网站建设,网站永久空间,甘肃省建设厅网站资质升级公示,义乌万物网络科技 网站建设本文内容 使用 C# 索引器实现 C# 的 is 和 as 关键字实现 C# 的 lock 关键字 本节中的主题介绍如何在 Visual C 中创建程序集,这些程序集使用或提供以 C# 或 Visual Basic 编写的程序集的功能。 1、使用 C# 索引器 Visual C 不包含索引器;它具有索引…

本文内容

  1. 使用 C# 索引器
  2. 实现 C# 的 is 和 as 关键字
  3. 实现 C# 的 lock 关键字

本节中的主题介绍如何在 Visual C++ 中创建程序集,这些程序集使用或提供以 C# 或 Visual Basic 编写的程序集的功能。

1、使用 C# 索引器

Visual C++ 不包含索引器;它具有索引属性。 若要使用 C# 索引器,请访问索引器,就像它是索引属性一样。

示例

以下 C# 程序定义索引器。

// consume_cs_indexers.cs
// compile with: /target:library
using System;
public class IndexerClass {private int [] myArray = new int[100];public int this [int index] {   // Indexer declarationget {// Check the index limits.if (index < 0 || index >= 100)return 0;elsereturn myArray[index];}set {if (!(index < 0 || index >= 100))myArray[index] = value;}}
}
/*
// code to consume the indexer
public class MainClass {public static void Main() {IndexerClass b = new IndexerClass();// Call indexer to initialize elements 3 and 5b[3] = 256;b[5] = 1024;for (int i = 0 ; i <= 10 ; i++)Console.WriteLine("Element #{0} = {1}", i, b[i]);}
}
*/

此 C++/CLI 程序使用索引器。

// consume_cs_indexers_2.cpp
// compile with: /clr
#using "consume_cs_indexers.dll"
using namespace System;int main() {IndexerClass ^ ic = gcnew IndexerClass;ic->default[0] = 21;for (int i = 0 ; i <= 10 ; i++)Console::WriteLine("Element #{0} = {1}", i, ic->default[i]);
}

此示例产生以下输出:

Element #0 = 21
Element #1 = 0
Element #2 = 0
Element #3 = 0
Element #4 = 0
Element #5 = 0
Element #6 = 0
Element #7 = 0
Element #8 = 0
Element #9 = 0
Element #10 = 0

2、实现 C# 的 is 和 as 关键字

本主题演示如何在 Visual C++ 中实现 C# 的 is 和 as 关键字的功能。

示例

// CS_is_as.cpp
// compile with: /clr
using namespace System;interface class I {
public:void F();
};ref struct C : public I {virtual void F( void ) { }
};template < class T, class U >
Boolean isinst(U u) {return dynamic_cast< T >(u) != nullptr;
}int main() {C ^ c = gcnew C();I ^ i = safe_cast< I ^ >(c);   // is (maps to castclass in IL)I ^ ii = dynamic_cast< I ^ >(c);   // as (maps to isinst in IL)// simulate 'as':Object ^ o = "f";if ( isinst< String ^ >(o) )Console::WriteLine("o is a string");
}

输出结果:

o is a string

3、实现 C# 的 lock 关键字

本主题演示如何在 Visual C++ 中实现 C# lock 关键字。

示例

// CS_lock_in_CPP.cpp
// compile with: /clr
using namespace System::Threading;
ref class Lock {Object^ m_pObject;
public:Lock( Object ^ pObject ) : m_pObject( pObject ) {Monitor::Enter( m_pObject );}~Lock() {Monitor::Exit( m_pObject );}
};ref struct LockHelper {void DoSomething();
};void LockHelper::DoSomething() {// Note: Reference type with stack allocation semantics to provide// deterministic finalizationLock lock( this );// LockHelper instance is locked
}int main()
{LockHelper lockHelper;lockHelper.DoSomething();return 0;
}

 

 

http://www.yayakq.cn/news/139471/

相关文章:

  • seo网站架构设计宁波公司注册流程
  • 苏州制作企业网站公司wordpress编辑网站
  • 中建豪城建设有限公司网站公司牌子设计图
  • 做建站较好的网站珠海 网站建设
  • 营销型网站 案例成都商城类网站设计
  • 求职招聘网站开发网站名称 注册
  • 网站更改机房备案一个网站开发小组
  • 哈尔滨市建设工程信息网官方网站工程承包去哪个网站
  • wordpress仿站教程2018建设网站经验
  • 山西省三基建设办公室网站宝山区网站建设
  • 网站备案 暂住证社交网站的优点和缺点
  • 精仿手表网站android开发流程
  • 网站公司倒闭商丘做网站一般多少钱
  • 网页制作的过程企业网站优化链接
  • 网站带后台网站 在线支付功能
  • 做鼻翼整形整形的网站国内知名网站建设
  • 朱子网站建设微网站建设公司哪家好
  • 做爰全过程免费网站的视频教程濮阳市做网站
  • 泸州建设工程质量监督网站购物网站的建设
  • saas建站平台有哪些什么网站可以做微招聘
  • 国内比较高端的设计网站上海网站seo设计
  • 南县网页定制长沙谷歌seo
  • 长沙网站制作作平顶山市网站建设公司
  • 牟长青 做网站推广的四个基本要点域名注册网站
  • 唐山市住房和城乡建设局网站个人简历免费模板下载
  • 学做网站要多久多少钱免费下载app软件并安装手机
  • cakephp网站开发框架做网站素材图片
  • 做旅游网站的yi义乌做网站多少钱
  • 临淄区住房和城乡建设局网站wordpress 加载图片
  • 长沙网站营销在国外网站付款要怎么做