Please help...from C# to VB

J

JC Voon

Hi :

I'm new to VB and C#, can someone help me to convert this code to VB

1. The following code, what is the 'this' means ?
public object this [int index]
{
get {return ((IDataRecord)myObj)[index];}
}

2. What is the different using 'this' and 'base' ?
public class MyClass
{
public MyClass(int Param1)
: base (Param1, 123)
{
}
// the above block can i change to ..??
//public MyClass(int Param1)
//{
// base.MyClass(Param1, 123)

// }

public MyClass(int Param1, int Param2)
: this (Param1)
{
...
}
}


Is this conversion correct ?

public class MyClass
public sub New(Param1 AS Integer)
MyBase.New(Param1, 123) ' or MyClass.New(Param1, 123) ???
end sub

public sub New(Param1 AS Integer, Param2 AS Integer)
Me.New(Param1, 123)
...
end sub
end class


Thanks
JCVoon
 
S

Shiva

1. It refers to the indexer implementation of a class (also known as default
property). For more info on this:
http://msdn.microsoft.com/library/en-us/csref/html/vclrfIndexedPropertiesPG.asp?frame=true

2. MyClass is a keyword in VB .NET, so it can't be used for class names.
Also, this class doesn't derive from any class that takes two parametes for
its constructor, so MyBase.New(Param1, 123) will not work. Finally, the
constructor cannot call itself (Me.New(Param1, 123))

HTH.

Hi :

I'm new to VB and C#, can someone help me to convert this code to VB

1. The following code, what is the 'this' means ?
public object this [int index]
{
get {return ((IDataRecord)myObj)[index];}
}

2. What is the different using 'this' and 'base' ?
public class MyClass
{
public MyClass(int Param1)
: base (Param1, 123)
{
}
// the above block can i change to ..??
//public MyClass(int Param1)
//{
// base.MyClass(Param1, 123)

// }

public MyClass(int Param1, int Param2)
: this (Param1)
{
...
}
}


Is this conversion correct ?

public class MyClass
public sub New(Param1 AS Integer)
MyBase.New(Param1, 123) ' or MyClass.New(Param1, 123) ???
end sub

public sub New(Param1 AS Integer, Param2 AS Integer)
Me.New(Param1, 123)
...
end sub
end class


Thanks
JCVoon
 
J

JC Voon

Shiva, Jorge Serrano:

Thanks for the reply.

I use the converter from
http://www.aspalliance.com/aldotnet/examples/translate.aspx

The following C# code.....

public object this [int index] // Indexer declaration
{
get {return ....;}
}


After convert to VB.....

Default Public ReadOnly Property Item(ByVal index As Integer) As
Object
Get
Return ...
End Get
End Property

The 'this' keyword in C# is convert to 'Item', but some of the
converter (can't remember which one) convert to 'Me' and some of it
convert to 'Blubber', doest it means i can simply put any name i like
?

Thanks

Regards
JCVoon
 
S

Shiva

I feel 'Item' (with Default keyword) is more appropriate (thats what being
used in .NET base class libaries also). But, practically it can be any name
but not Me because its a keyword in Visual Basic .NET.

HTH

Shiva, Jorge Serrano:

Thanks for the reply.

I use the converter from
http://www.aspalliance.com/aldotnet/examples/translate.aspx

The following C# code.....

public object this [int index] // Indexer declaration
{
get {return ....;}
}


After convert to VB.....

Default Public ReadOnly Property Item(ByVal index As Integer) As
Object
Get
Return ...
End Get
End Property

The 'this' keyword in C# is convert to 'Item', but some of the
converter (can't remember which one) convert to 'Me' and some of it
convert to 'Blubber', doest it means i can simply put any name i like
?

Thanks

Regards
JCVoon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top