1

I created a class with properties like this

public class Dependencies
{
    public string issueID { get; set; }
    public string status { get; set; }
    public int dependencyCheck { get; set; }
}

Now I created a method where i can use these properties.

private static void prepareIssuesList(string IssueKey, string JIRAtoken)
{
    Dependencies dpObj = new Dependencies();
    List<Dependencies> listObj = new List<Dependencies>();
    dpObj.issueID = IssueKey;
    dpObj.status = "open";
    dpObj.dependencyCheck = 0;
    listObj.Add(dpObj);

}

Now my question is, how to change the dependencyCheck property value. The prepareIssuesList() can called for multiple times. So i am adding multiple objects to Dependencies class. At certain point of time i want to change the dependencyCheck property value. How to do this. I think need to use the Linq to C#. ICan any one have any solution for this one?

14
  • which one do you want to change? all of them? Commented Jun 13, 2012 at 12:09
  • what do you mean, "change the dependencyCheck property value"? You just have to assign it... Linq has nothing to do with it Commented Jun 13, 2012 at 12:09
  • 2
    your listObj seems to be not stored at all, so each time you call preapreIssuesList, it's going to be a new one, right? Commented Jun 13, 2012 at 12:09
  • 1
    This code doesn't seem complete. prepareIssuesList() is creating a local list and never returning it or saving it anywhere. Commented Jun 13, 2012 at 12:10
  • 3
    Why is this downvoted? How about we all allow the non-native english speaker to try to explain her/his problem first? Commented Jun 13, 2012 at 12:11

1 Answer 1

4

I would do something along these lines:

public class Dependency
{
     public string IssueId { get; set; }
     public string Status { get; set; }
     public int DependencyCheck { get; set; }
}

public class DependencyManager
{
     public DependencyManager()
     {
          this.Dependencies = new List<Dependency>();
     }         

     public List<Dependency> Dependencies { get; private set; }

     public void AddDependency(string issueId)
     {
         var dep = new Dependency();
         dep.IssueId = issueId;
         dep.Status = "open";
         dep.DependencyCheck = 0;

         this.Dependencies.Add(dep);
     }

     public void SetDependencyCheck(string issueId, int value)
     {
         var dep = this.FindDependencyByIssueId(issueId);
         dep.DependencyCheck = value;
     }

     public Dependency FindDependencyByIssueId(string issueId)
     {
         var dep = this.Dependencies.FirstOrDefault(d => d.IssueId.Equals(issueId));
         if(dep == null) throw new ArgumentException("Dependency not found", "issueId");
         return dep;
     }
}

Then somewhere in your code you could do:

var mgr = new DependencyManager();
mgr.AddDependency("ABC123");
mgr.AddDependency("ABC456");

//... some other stuff that makes sense

mgr.SetDependecyCheck("ABC123", 42);
Sign up to request clarification or add additional context in comments.

11 Comments

+1 Although it would be worthy explaining why OP's code didn't work (because a new List instance was being created on each call).
@Klaus.. Thanks. Really I am feeling so much shy that i dont know that how to code like this.. really awesome.
@YSSS You are welcome. Just keep practicing and asking questions here and your skills will definitely improve with time.
@KlausByskovHoffmann the code what you present here also not storing values.
@YSSS hehe ok. I think you are not aware of when values are stored and when not. As long as the mgr instance is in scope, it holds all the values you put into it. When the mgr runs out of scope it gets "lost". Since I don't know the structure of your code, I cannot recommend how to best store the instance.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.