Getting CS1513 } Expected, but all braces are there [closed] - c#

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 9 years ago.
Improve this question
I'm a novice programmer, so forgive me if this is something obvious. I've checked all the braces and find matching pairs in all cases here. The code compiles fine without this snippet. Any ideas?
protected bool Bullish(int ConsecutiveBullishBars)
{
private int howmanybars = ConsecutiveBullishBars - 1;
private bool IsMarketBullish = false;
while (howmanybars >= 0)
{
if (Close[howmanybars] > KeltnerChannel(Offset, Period)[howmanybars])
{
IsMarketBullish = true;
}
else
{
IsMarketBullish = false;
}
howmanybars--;
}
return IsMarketBullish;
}
Here is the full code: http://pastebin.com/aHbzqKbw

It doesn't make any sense to mark local method variables as private. That is what is causing your errors.
Why the compiler is giving you an } expected error, I'm not sure. I'm guessing that the compiler is assuming that private int howmanybars is being interpreted as a private instance field definition, which cannot be declared inside a method. So it is telling you that it expects the Bullish method to end before the declaration.
protected bool Bullish(int ConsecutiveBullishBars)
{
int howmanybars = ConsecutiveBullishBars - 1;
bool IsMarketBullish = false;
while (howmanybars >= 0)
{
if (Close[howmanybars] > KeltnerChannel(Offset, Period)[howmanybars])
{
IsMarketBullish = true;
}
else
{
IsMarketBullish = false;
}
howmanybars--;
}
return IsMarketBullish;
}

Related

Can’t get a specific output using a boolean [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want a specific output depending on wether the Boolean is set to true or not. I can’t seem to find the solution so I’m just asking here. I don’t what to output „true“ or „false“ but a specific text.
What I tried:
public class Program
{
bool isAlive = true;
public static void Main()
{
if (isAlive == true){
Console.WriteLine("Is True");
}
}
}
What worked:
public class Program
{
public static void Main()
{
bool isAlive = true;
if (isAlive == true){
Console.WriteLine("Is True");
}
}
}
The Error was that I tried to use the non-static variable in the static void. Thanks to everyone that helped.
you can do either
string output = bool_variable ? "true value" : "false value";
Debug.Log(output);
or
if(bool_variable == true){
Debug.Log("true value")
}else{
Debug.Log("false value")
}
Edit:
You are getting the non-static error because you are trying to access isAlive from a static method when it is not static. So you either need to create an instance of Program, make isAlive static, or remove the static keyword from Main.
Further more this does not seem to be a unity question since you are using Console.WriteLine and not implementing MonoBehaviour
You can use the following code
{boolean_variable} ? "Boolean value is true" : "Boolean value is false"

Capturing return value from helper class c# [closed]

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 5 years ago.
Improve this question
I've spent the better part of an hour reading over linked items on Google about this topic; however, maybe it just is not sinking in. What do I need to do to capture the return value from a helper class in C#? This is the code:
protected void Page_Load(object sender, EventArgs e)
{
HelperClass.Calculate(a, b);
}
public static string Calculate(string a, string b)
{
string value = string.Empty;
// inner code workings
return value;
}
I know I'm missing something but I cannot for the life of me determine what. Any help would be appreciated! Thank you!
var x = HelperClass.Calculate(a, b);
Just like any other function, which returns a value?
protected void Page_Load(object sender, EventArgs e)
{
string value = HelperClass.Calculate(a, b);
}
public static string Calculate(string a, string b)
{
string value = string.Empty;
// inner code workings
return value;
}

The modifier "private" in not valid for this item c# [closed]

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 5 years ago.
Improve this question
I dont know what to do, im new to whole coding and the project im working on is going quite well, tried adding more commands and this problem jumps to the first private part here. If needed i can send the rest of the code
RegisterYNCommand();
{
}
private void RegisterYNCommand();
{
{
Commands.CreateCommand("YN")
.Do(async (e) =>
{
int yesnoIndex = rand.Next(randomTexts.Length);
string memeToPost = yesno[yesnoIndex];
await e.Channel.SendMessage(memeToPost);
});
Remove the first
RegisterNYCommand();
{
}
Looks like duplicated code...
and the ; at the end of
private void RegisterNYCommand(); // This ';'
{
Commands.CreateCommand("YN")
.Do(async (e) =>
{
int yesnoIndex = rand.Next(randomTexts.Length);
string memeToPost = yesno[yesnoIndex];
await e.Channel.SendMessage(memeToPost);
});
}
Just remove ; character after your methods declaration:
private void RegisterYNCommand()
{

Function won't return any value [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
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.
Improve this question
I have a problem that I think might be really easy to solve but since I'm a C# noob I can't understand what I'm doing wrong. I have two functions: addValues() and showMessage(). My problem is in addValues(). I have two MessageBox that show exactly what they're supposed to show, but in the showMessage() function the values are not being received, it always tells me that the day and dias.Count are 0. What am I doing wrong? Thank you!
On Form1:
public List<Despesas> dias = new List<Despesas>();
public struct Despesas
{
public double transportes;
public double alimentacao;
public double vestuario;
public double agua;
public double luz;
public double educacao;
}
On Class Management:
class management : Form1
{
int day=0;
public double addValues(double transportes, double alimentacao)
{
Despesas dia = new Despesas();
try
{
dia.transportes = transportes;
dia.agua = agua;
dias.Add(dia);
}
catch
{
MessageBox.Show("Error", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show("Count " + dias.Count);
day++;
MessageBox.Show("" + day);
return day;
}
public void showMessage()
{
MessageBox.Show("Day " + day);
MessageBox.Show("Count: " " + dias.Count);
for (int i = 0; i < day; i++)
{
MessageBox.Show("Agua: " + dias[i].agua + "\nTransportes: " + dias[i].transportes);
}
}
In the comments, you mention that you actually have two instances of the management class.
Changes to one instance of an object do not propagate to other instances of that object (unless it was modified on a static member, but thats a bit different).
This holds true even if you modify a base class member, as your code does. This is because instantiation of a derived class also instantiates a new base class object.
The solution is to just use one management object instance, and pass it around as needed. You do this just like any other type:
public void Foo(management myClass)
{
...
}
A few other notes:
management is not a very good name for a class, as its not very descriptive. Also, class names in C# should be PascalCase, so it should be Management
Inheritance is probably not the right relationship between management and Form1. Is management really a "type of" or "is a" Form1?

system.timers.timer autoreset default value [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I just want to know the default value of this property.
I thought it was false, but it seems to be true.
I spent 5 min to look for this question and it perhaps make someone not loosing this time in the futur...
Answer from msdn The default is true:
http://msdn.microsoft.com/en-us/library/system.timers.timer.autoreset%28v=vs.110%29.aspx
Answer from Reflector default value = true:
public Timer(double interval) : this()
{
...
}
public Timer()
{
this.interval = 100.0;
this.enabled = false;
//HERE!!!!
this.autoReset = true;
this.initializing = false;
this.delayedEnable = false;
this.callback = new TimerCallback(this.MyTimerCallback);
}

Categories

Resources