Conversion VB.NET to C#

  • Thread starter Fabio Negri Cicotti [MCP]
  • Start date
F

Fabio Negri Cicotti [MCP]

Another question about convertions... how could I convert the code below to
C#?

Public Property Value(ByVal index As Integer) As String
Get
Value = dt.Rows(index).Item(MyBase.ValueMember)
End Get
Set(ByVal value As String)
dt.Rows(index).Item(MyBase.ValueMember) = value
End Set
End Property


Grateful again.
 
P

Peter Jausovec

Hi,

It should be like this:

public string Value [int index]
{ ... }

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
Fabio Negri Cicotti said:
Jason,

I got the following code but I not sure about it! Where does the index is
passed from?


public string Value {
get {
Value = dt.Rows(index).Item(base.ValueMember);
}
set {
dt.Rows(index).Item(base.ValueMember) = value;
}
}
 
F

Fabio Negri Cicotti [MCP]

To be as clear as possible, what I'm looking for is create a user control
where I can access the values passing an index like that:

myObject[0].Value = "Test";

So, how can I do it?


Regards,
 
D

David Anton

C# does not support general parameterized properties, but our Instant
C# VB.NET to C# converter gives the following conversion:

//ORIGINAL LINE: Public Property Value(ByVal index As Integer) As
String
//INSTANT C# WARNING: C# does not support parameterized properties -
the following property has been divided into two methods:
public string Value(int index)
{
return dt.Rows;
}
public void SetValue(int index, string value)
{
dt.Rows[index][base.ValueMember] = value;
}


Feel free to download our free (and supported) Demo Edition at
www.instantcsharp.com

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
M

Mike Newton

Fabio said:
To be as clear as possible, what I'm looking for is create a user control
where I can access the values passing an index like that:

myObject[0].Value = "Test";

So, how can I do it?


Regards,


Dude...

If your property is a string, you're not going to be able to set a
"Value" property of your property. "Value" isn't a member of the String
class.

If you want the row collection returned, just do something like:

public TableRowCollection myObject{
get{
return dt.Rows;
}
}

You don't need the set statement, since you aren't going to be able to
set the row collection. ie.

myObject["ColumnName"].Value = blah

With this, you can reference a row with your index by myObject.
You're not going to be able to reference a row and a column with just a
property. If you need to do this, it's probably best to write a function.


That is, unless your 'dt' isn't a datatable. If it isn't, you haven't
provided enough information.
 
Y

Yusuf INCEKARA

set index in somewhere.

private string _Value;
private int index;
public string Value
{
get
{
return dt.Rows(index).Item(MyBase.ValueMember);
}
set
{
dt.Rows(index).Item(MyBase.ValueMember) = value;
}
}
 
R

Ravichandran J.V.

public string Value
{
get
{
Value = dt.Rows(index).Item(MyBase.ValueMember)
}
set
{
dt.Rows(index).Item(MyBase.ValueMember) = value
}
}

Why do you wish to use the keyword 'Value" ?

with regards,


J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com
 

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