Possible Duplicates:
IF structure issue
Logic problem while setting conditions
I have the following code:
foreach (DataModelObject dmo in allObjects)
{
if (string.Compare(dmo.Name, hostName, true) == 0)
{
if (dmo is IResourcePolicy)
{
IResourcePolicy irp = (IResourcePolicy)dmo;
irp.ResourcePolicy = rp;
irp.AgentPolicyVersion.Version = Convert.ToInt64(policyVersion);
irp.ResourcePolicyEnabled = Convert.ToBoolean(enabled);
irp.AgentVersion = agentVersion;
// Distribute the object without saving it.
SpoServer.Spurt.ServerSendObject(dmo, true, 0);
break;
}
}
}
here i want to assign "irp.AgentVersion = agentVersion;" outside of the main loop and more over neglecting the loop if (dmo is IResourcePolicy) like this way if i am doing this way
foreach (DataModelObject dmo in allObjects)
{
IResourcePolicy irpa ;
irpa.AgentVersion = agentVersion;
}
i am getting error Error Use of unassigned local variable 'irpa'
what shall i do here?