Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello....

I was translating VB code to C# .... And I am unable to get the solution of this IndexOf method .... please help me out....

C# code is...
show_classroom_link = (Convert.ToInt32(emp_rs["classroom_program_count"]) > 0) || (emp_rs["security_group_list"].IndexOf(",14,") + 1 > 0);


VB Code is...
show_classroom_link = (emp_rs.Item("classroom_program_count") > 0) or (InStr( emp_rs.Item("security_group_list"), ",14,") > 0)

Error: The object does not contain the definition for &#39;IndexOf&#39;...</pre>
Posted
Updated 14-Jun-15 20:07pm
v2
Comments
Ralf Meier 15-Jun-15 1:56am    
I can't see the usage of the .IndexOf inside your posted VB-Code ...
Plaese complete it.
Or ... use it in C# in the same way as it was used in VB ...

Change
(emp_rs["security_group_list"].IndexOf(",14,") 

to
(Convert.ToString(emp_rs["security_group_list"]).IndexOf(",14,") 
 
Share this answer
 
I think if emp_rs.Item("security_group_list") is a string field. if it is may be just check

emp_rs.Item("security_group_list").Contains(",14,")

Just a wild guess.
 
Share this answer
 
Comments
sasanka sekhar panda 15-Jun-15 6:06am    
Contains().returns a bool value ..so how to compare bool>0 or not
jdeep84 16-Jun-15 2:57am    
thats what if indexof returns greater than 0 it means provided string occurs/present in source string. I think the end result is bool which decides to show the link or not. Hope this make sense.
sasanka sekhar panda 16-Jun-15 5:09am    
correct...
C#
//corrected code
show_classroom_link = (Convert.ToInt32(emp_rs["classroom_program_count"]) > 0) || (emp_rs["security_group_list"].ToString().IndexOf(",14,") > 0);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900