Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Showing error in line 3.
Code in Below
if (this.Page.Master != null)
{
Control TargetControl;
if (this.Page.Master.FindControl(this.TargetControlID) != null)
{
return this.Page.Master.FindControl(this.TargetControlID);
}
return TargetControl;
}
Change your code to just this:
return Page.Master.FindControl(TargetControlID);
This will either return null if its not found or it'll return the control.
Use of unassigned local variable 'TargetControl'
Your error is because you're declaring a variable here:
Control TargetControl;
But never assigning it a value. You must assign values to variables before using them.
The quick solution is this:
Control TargetControl = null;
..but then, that is pretty useless in itself, you can just do this:
return this.Page.Master.FindControl(this.TargetControlID);
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am working on some APIs that hit other APIs, testing them, and then storing results in a Postgres. I've already completed other sections of it with using EF and async/await so the following code block is essentially a copy/paste..
public async Task<OperationResponse> UpsertEvents(ILogger log, MCVPEvent eventToAdd, ICollection<MCVPEventStep> eventStepsToAdd)
{
int saveResult;
long saveResultId;
try
{
var eventDto = this.mapper.Map<MCVPEventDto>(eventToAdd);
eventDto.MCVPEventSteps = this.mapper.Map<ICollection<MCVPEventStepDto>>(eventStepsToAdd);
var addResult = await this.dbContext.MCVPEvents.AddAsync(eventDto);
// this following line blows up-->
saveResult = await this.dbContext.SaveChangesAsync();
saveResultId = eventDto.Id;
log.LogInformation($"SaveChangesAsync result: {saveResult} and id: {saveResultId}");
return Operation.Success();
}
catch (Exception ex)
{
log.LogInformation($"DbUpdateException: {ex.Message}");
return Operation.Exception(ex);
}
}
but for the life of me I cannot figure out why the container keeps disposing of the context after I call Add... I've tried it with AddAsync and then SaveChangesAsync; I've tried it with just regular non-async Add and then SaveChangesAsync; it only seems to work when I use both of the non-async methods Add and SaveChanges.
Is it because I am calling other methods, like mapper or log during all this? Is it because my return values are not entities?
Don't forget to await the calling method, in my case UpsertEvents(..)!
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
void Update ()
{
if (transform.Translate((Input.acceleration.x), 0, 0))
{
GetComponent<Rigidbody>().AddForce(Vector2.right);
}
}
I am using the accelerator for a Android App and doesn't seem to like it. I can change it to work for KeyDown but it wont work with the accelerator.
Error:
"Cannot implicitly convert type "void" to "bool"
According to the documentation http://docs.unity3d.com/ScriptReference/Transform.Translate.html:
transform.Translate does not return a boolean; its return type is void. Therefore you cannot use an if statement to evaluate whether or not it was successful.
If you want to check to see if the translate happened correctly you would need to check the side effects from calling transform.Translate. In other words see what has changed on the transform and see if it matches your expectations.
Don't use the if statement, as Translate returns nothing. Just leave the AddForce line
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Here is my function:
public void PowerupCollected(int AddScore)
{
score += AddScore;
scoreGUI.text = "lol"+score;
}
Here is how I call that function:
if(other.gameObject.name == "Powerup(Clone)")
{
control.PowerupCollected();
}
here is the error message
error CS1501: No overload for method `PowerupCollected' takes 0 arguments
What is wrong? Is it because I don't include AddScore when in brackets when I call the function?
Either add the AddScore argument to your call (say control.PowerupCollected(42); or make the argument optional: public void PowerupCollected(int AddScore = 0).
Since second solution doesn't make sense in your case, i'd use first one.
Your function call should include the amount of score you want to add:
if(other.gameObject.name == "Powerup(Clone)")
{
control.PowerupCollected();
}
should be (for example):
if(other.gameObject.name == "Powerup(Clone)")
{
control.PowerupCollected(10);
}
This would add 10 to your score.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Simple question I think. I am trying to pass in a list that I created within my Main into a method. I am missing something but can't quite put my finger on it.
Declaration
List<string> emulationList = new List<string>();
Method Call
sataHeader = ParseSataHeader(sataHeader, bcuFileName, List<string> emulationList);
Method Implementation
private static string ParseSataHeader(string sataHeader, string bcuFileName, List<string> emulationList)
{
//some code
}
You don't specify the type when passing arguments.
Change your second snippet to:
sataHeader = ParseSataHeader(sataHeader, bcuFileName, emulationList);
And it will work just fine.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I've seen code where the developer assigns properties or local variables from an if statement after performing some method call.
Example:
void SomeMethod()
{
MyObject myObject;
if ((myObject = DoSomething()) != null)
{
//Do some business logic
}
}
I think it gets very messy when a lot of these assignments are happening, or there is more going on in the if-statement, such as accessing an array.
I personally prefer something like this:
void SomeMethod()
{
MyObject myObject = DoSomething();
if (myObject != null)
{
//Do some business logic
}
}
Is there any benefit of the first piece of code over the second example? Any miniscule efficiency gains or anything? I want to know if I'm missing something.
A large piece of the code set is becoming nested with this style of code which I believe is less readable.
There is no performance implications to this change - it is a matter of personal preference. This works because an assignment is a value-producing expression, which can be used in comparison or other expressions. The idea is to "fold" the assignment into the header of a conditional, essentially saving a line of code.
Although this makes no difference with a single if (the number of lines does not change) it does make a difference for longer chains of conditionals. It is also useful in loops, for example
int ch;
while ((ch = reader.Read()) != -1) {
// Do something with ch
}