Our VB to C# converter (Instant C#) produces the following - note that:
1. Although in your example you could safely ignore it, in general you have
to account for the fact that the ending condition of a VB for loop is checked
only once while the ending condition of a C# for loop is checked every
iteration.
2. You need to return a value for every code path in C# - usually C#
developers will just add the default statement at the end of the function
when they get this warning (VB does this for you behind the scenes).
public int GetSelIndex(str ing CatID)
{
int iLoop = 0;
//Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tabl es["Categories "];
int tempFor1 = dt.Rows.Count;
for (iLoop = 0; iLoop < tempFor1; iLoop++)
{
if (Int32.Parse(Ca tID) ==
Int32.Parse(dt. Rows[iLoop]["FAQCategor yID"]))
{
return iLoop;
}
}
//INSTANT C# NOTE: Inserted the following 'return' since all code paths
must return a value in C#:
return 0;
}
David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter and the Instant VB C# to
VB.NET converter
"Andy Sutorius" wrote:
Hi,
I am attempting to convert this vb function to csharp but I am getting stuck
on the if statement dt.Rows(iLoop)( "FAQCategoryID" )). The compiler says
"method name expected" and underlines dt.Rows[iLoop]. I don't understand.
Thanks for your help.
Function GetSelIndex(Cat ID as String) as Integer
Dim iLoop as Integer
'Loop through each row in the DataSet
Dim dt as DataTable = ddlDataSet.Tabl es("Categories" )
For iLoop = 0 to dt.Rows.Count - 1
If Int32.Parse(Cat ID) = Int32.Parse(dt. Rows(iLoop)("FA QCategoryID"))
then
Return iLoop
End If
Next iLoop
End Function
public int GetSelIndex(str ing CatID)
{
int iLoop;
// Loop through each row in the DataSet
DataTable dt = ddlDataSet.Tabl es["Categories "];
int rowCount = dt.Rows.Count-1;
for (iLoop=0; rowCount <= iLoop; iLoop++)
if (Int32.Parse(Ca tID) = Int32.Parse(dt. Rows[iLoop]("id")))
{
return iLoop;
}
}