C
Join ServerC#
help
❔ can't make it Public
IItgel1/26/2023
Hi guys. There's some type problem. Please help me out.
I want to declare that variable named 「string Result」 in other place. To do so I changed its type to public. (made it "public string Result;") Then I got errors. How can I make this variable accessible?
I want to declare that variable named 「string Result」 in other place. To do so I changed its type to public. (made it "public string Result;") Then I got errors. How can I make this variable accessible?


Jjalepi1/26/2023
You want to make it a class field? Move it to the class body, like just before the method definition
IItgel1/27/2023
This Class1.cs file represents this code that got error. I want to declare this string type variable in Mainwindow.xaml.cs. I think the type must be public to be accessible, so I tried to make it public up there, and having errors.

IItgel1/27/2023
Sorry for that, I'm totally new at programming. I can't figure it out how to make it accessible. I have questions. Is class body determined? And this class1.cs is not fitting the class body? that's why i cannot access to this program from out of outside.
Jjalepi1/27/2023
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/fields
At learn.microsoft there are several courses and it's a good starting point for beginners
At learn.microsoft there are several courses and it's a good starting point for beginners
SShinyshark1/27/2023
Just to clarify, your issue is regarding scopes. In C# programming (and other languages too, I would assume) you can create resources in scopes. @Itgel

SShinyshark1/27/2023
So you have a few scopes in your screenshot. I marked them with arrows for you.
SShinyshark1/27/2023
Scopes can access scopes inside of them, but not the other way around.
SShinyshark1/27/2023
If you want to use your result string inside of the entire method, you have to declare it in the method scope. Above the
using (var audioConfig)
line.SShinyshark1/27/2023
The reason you cannot make this string public is because your method scope does not support access modifiers.
SShinyshark1/27/2023
Access modifiers are part of objects, like your class.
SShinyshark1/27/2023
Your method cannot contain something public because you cannot reach inside the method to grab it.
SShinyshark1/27/2023
I hope that makes sense to you. It is hard to explain your issue without going into a little bit of detail.
IItgel1/27/2023
Thank you man. Thank you so much. I feel like I understand something a bit. That means I cannot make it public by only writing "public string Result" in this class. What I have to do is, change a method scope to make it accessible variable right?
SShinyshark1/27/2023
Why do you want the result variable to be public?
SShinyshark1/27/2023
If you tell me that I can help you understand where you should place it / why.
IItgel1/27/2023
This string Result is the string that I get it as a result from speech recognition API. I want to create a subtitle box in main program. To do so, I want to grab string Result from this class1.cs and declare in main program to create the subtitle box.
Here is a main program. x_coordinate.Text is the variable that represents subtitle string.
Here is a main program. x_coordinate.Text is the variable that represents subtitle string.

IItgel1/27/2023
Is that clear to understand?
SShinyshark1/27/2023
Sure, can you hover over the Result so I can see the error?
IItgel1/27/2023
like this?

SShinyshark1/27/2023
Ah, I see.
SShinyshark1/27/2023
You have to make a public property called Result in your AzureAPI class
SShinyshark1/27/2023
And then instead of using a local variable, set your result to that.
SShinyshark1/27/2023
put your public result here

SShinyshark1/27/2023
above the method, under the class.
SShinyshark1/27/2023
you can type
SShinyshark1/27/2023
public string Result { get; set; }
IItgel1/27/2023

IItgel1/27/2023
Sorry. I got the same error as how I wrote before Public string Result;
SShinyshark1/27/2023
What is the error in the AzureAPI?
SShinyshark1/27/2023
I reckon it will be related to the method being static.
IItgel1/27/2023

SShinyshark1/27/2023
Remove the ' static' from your FromMic method.
IItgel1/27/2023
No errors after removing static
SShinyshark1/27/2023
It's difficult to explain to you what static does
IItgel1/27/2023
Now is it accessible?
SShinyshark1/27/2023
because it requires a bit of pre-knowledge.
SShinyshark1/27/2023
It should be yeah. If you call FromMic, it will set your Result.
SShinyshark1/27/2023
You can then grab your Result.
SShinyshark1/27/2023
It's hard for me to see what you want to do, but your Result issue is solved.
SShinyshark1/27/2023
If you want to learn a bit more, read into scopes and static.
SShinyshark1/27/2023
Static is often used by people as a solution for their issues when they do not understand their issue.
SShinyshark1/27/2023
In your situation, your editor likely told you to mark your method as static.
IItgel1/27/2023
Thank you so much*1000000
SShinyshark1/27/2023

IItgel1/27/2023
Sorry to bother you again. If you have some time let me ask you again 😅 . If you have not, Don't force yourself.
I tried to call the method From mic in main program. But still got a error. I changed speechConfig to Result and it didn't work. Why?
I tried to call the method From mic in main program. But still got a error. I changed speechConfig to Result and it didn't work. Why?

SShinyshark1/27/2023
speechConfig is not set.
SShinyshark1/27/2023
You need a SpeechConfig object to pass along
AAccord1/28/2023
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.