什么是VB中DirectCast的等效C#代码? [英] what is Equivalent C# code for DirectCast in VB?

查看:66
本文介绍了什么是VB中DirectCast的等效C#代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Dim  intListPrice  As  整数 =  0  
Dim rowList 作为 集合
Dim intCoutner 作为 整数 = 1

intListPrice = intListPrice + DirectCast (rowList(intcolCounter),对象())( 10





上述代码的含义是什么,等价物是什么上面代码中的c#代码? 

解决方案

要在C#中转换变量,只需在teh中输入teh值,并在括号中输入:

 MyType mt =(MyType) value ; 

所以在你的例子中它将是:

 intListPrice + =( int )rowList [ 10 ]; 


Dim intListPrice As Integer = 0
Dim rowList As New Collection
Dim intCoutner As Integer = 1

intListPrice = intListPrice + DirectCast(rowList(intcolCounter), Object())(10)



What is meaning of above code and what is the equivalent code in c# for above code? 

解决方案

To cast a variable in C#, you just prefix teh value to cast with teh type you want in brackets:

MyType mt = (MyType) value;

So in your example it would be:

intListPrice += (int) rowList[10];


这篇关于什么是VB中DirectCast的等效C#代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆