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

Below is my C# code............... I need to have a solution to use IndexOf method in the below code:


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



Error:
show_classroom_link = (Convert.ToInt32(emp_rs["classroom_program_count"]) > 0) || (emp_rs["security_group_list"].IndexOf(",14,") + 1 > 0);
Error Name:
'Object' does not contain a definition for 'IndexOf'

You all are requested to provide a solution for it...

Thanks
Posted
Comments
Thanks7872 15-Jun-15 5:12am    
Which part of error is not clear to you? It clearly states that 'Object' don't have such method. Why? Read about indexOf over internet : https://www.google.co.in/search?q=IndexOf&oq=IndexOf&aqs=chrome..69i57j69i59j69i60&sourceid=chrome&es_sm=93&ie=UTF-8#q=indexof+c%23

1 solution

C#
bool show_classroom_link = false;
//you can use IndexOf on a string
//It returns  zero-based index position of value if that string is found, or -1 if it is not. If value is String.Empty, //the return value is 0.
//Example
           string s = "abcdefg";
            Console.WriteLine(s.IndexOf("fg"));
            //o/p 5
            Console.WriteLine(s.IndexOf("b"));
            //o/p 1
            Console.WriteLine(s.IndexOf("z"));
           //o/p -1


//corrected code
       show_classroom_link = (Convert.ToInt32(emp_rs["classroom_program_count"]) > 0) || (emp_rs["security_group_list"].ToString().IndexOf(",14,") + 1 > 0);
       emp_rs.Close();
       emp_rs = null;
 
Share this answer
 
v3

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