0

In the following code, I get the following warning:

The variable 'Result' is assigned but its value is never used

 bool Result; base.ExecuteTest(delegate(Selenium.ISelenium sel1) { return Result = false; }); 

Furthermore, in the following code:

 for (int i = 0; i <= ClientSiteCnt; ) { return (Result = testcaseDel.Invoke()); } 

The delegate signature is

 public delegate bool TestCaseDelegate(Selenium.ISelenium sel); 

How do I add the parameter (the delegate's parameter) in the .Invoke() method?

5
  • 2
    Honestly, your code does not make any sense to me. Why are you assigning Result a value, then return it? If anything I would expect horrendous side effects, using and assigning a variable outside of the delegate. What are you trying to accomplish here? Commented Mar 4, 2010 at 10:19
  • Could you elaborate on the side effects? This seems like something I genuinely don't know. Commented Mar 4, 2010 at 10:30
  • Why would you have a for loop which always ends in the first iteration? Commented Mar 4, 2010 at 10:38
  • if you are using delegates, you need to understand how parameters are passend into and out of the delegate source, when the delegate will be executed and in what state the passed parameters are. And the Result you use is a parameter passed using a trick, the delegate is executed in a different execution frame and has no direct access to local variables of the calling execution frame. You really should explain what you want to achieve. Commented Mar 4, 2010 at 12:54
  • Thanks for the explanation. I've made some tweaks and fixed issues. Learnt something today! Commented Mar 4, 2010 at 14:45

2 Answers 2

1

about add parameter to Invoke method
you will just write it as

TestCaseDelegate testCaseDelegate =new TestCaseDelegate([method Name]); testCaseDelegate .Invoke([parameter of type Selenium.ISelenium]); 
Sign up to request clarification or add additional context in comments.

Comments

0

You get this message because you only assign a value to Result, but never use it.

What the compiler tries to tell you is: Why do you declare Result, assign values to it, but never use it?

Since you never use Result, your code samples will function exactly the same when you use:

 base.ExecuteTest(delegate(Selenium.ISelenium sel1) { return false; }); 

and

 // for (int i = 0; i <= ClientSiteCnt; ) // { return testcaseDel.Invoke(); // } 

2 Comments

Thanks for this answer. Yeah that is a much better example and I am going the way you've written too. Any idea on the second part of my post?
I think Space Cracker answered this for me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.