VB转C#转换问题 [英] VB to C# conversion problem

查看:95
本文介绍了VB转C#转换问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Asp.Net工作 - C#。



我在VB&运作良好

I'm working in Asp.Net - C#.

I've a coding in VB & is working well

Dim CLEAD As XmlSchemaElement
.
.
.

  reader = New XmlTextReader(xsdFilePath)
            schema = XmlSchema.Read(reader, Nothing)

            For i As Integer = 0 To schema.Items.Count - 1
                If TypeOf schema.Items(i) Is XmlSchemaElement Then
                    CLEAD = schema.Items(i)
                End If
            Next



我尝试将其转换为c#,如下所示


I tried to convert it into c# as follows

XmlSchemaElement CLEAD;
.
.
.
reader = new XmlTextReader(xsdFilePath);
 schema = XmlSchema.Read(reader, null);

 for (int i = 0; i < schema.Items.Count-1; i++)
            {

                 if (schema.Items[i].GetType() == typeof(XmlSchemaElement))
                     CLEAD = schema.Items[i];
            }





但这一行(CLEAD = schema.Items [i];)给出错误:无法隐式转换系统.Xml.Schema.XmlSchemaObject到System.Xml.Schema.XmlSchemaObjectElement



请帮我纠正这个



But this line (CLEAD = schema.Items[i];) gives the error: cannot implicitly convert System.Xml.Schema.XmlSchemaObject to System.Xml.Schema.XmlSchemaObjectElement

Please help me to rectify this

推荐答案

你可以明确地表达它(你已经检查了它的类型),例如

You may explicitely cast it (you've already checked its type), e.g.
CRMLEAD = (XmlSchemaElement)schema.Items[i];





或您可以使用作为运算符(参见MSDN [ ^ ])。



or you maight use the as operator (see MSDN[^]).


这篇关于VB转C#转换问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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