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
using System;
using System.IO;
using System.Security.Cryptography;
namespace Rextester{
public class Program{
public static void Main(string[] args){
String[,] name = {{"Juan", "Pérez"}, {"Fred", "Nurk"}, {"Marko", "Marković"}, {"Si", "Polan"}};
int place = 3;
String _name = (!String.IsNullOrEmpty(name[place,0])) ? $"Name: {name[{place},0]} {name[{place},1]}" : "Error";
Console.WriteLine(_name);
}
}
}
I try to use the integer place inside the String $"Name: {name[{place},0]} {name[{place},1]}" as identifier for the array name but the compiler give me these errors back:
Compilation error (line 9, col 74): Identifier expected
Compilation error (line 9, col 80): Syntax error, ',' expected
Compilation error (line 9, col 92): Identifier expected
Compilation error (line 9, col 98): Syntax error, ',' expected
Why the compiler would not compile these line? The identifier is given, so I don't understand the problem.
You already are inside curly brackets in the string, you don't need more curly brackets for each variable.
Not $"Name: {name[{place},0]} {name[{place},1]}"
But $"Name: {name[place,0]} {name[place,1]}"
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
Hi I have a question about my code. Everything should work without a problem, but when I try to print on the console, the stack gives me the following
input:
4
Output:
System.Collections.Generic.Stack1 [System.UInt64] System.Collections.Generic.Stack1 [System.UInt64] System.Collections.Generic.Stack1 [System.UInt64] System.Collections.Generic.
Stack1 [System.UInt64]
my question is if i need to add a new library because even with int it gives me the same.
using System;
using System.Collections.Generic;
namespace ConsoleApp29
{
class Program
{
static void Main(string[] args)
{
Stack<ulong> nm = new Stack<ulong>();
ulong p = ulong.Parse(Console.ReadLine());
for(ulong i = 0; i < p; i++)
{
nm.Push(i);
}
foreach(int i in nm)
{
Console.Write(nm);
}
}
}
}
nm, which you are printing, is the entire Stack object; you want to be printing i, the current element of nm.
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 3 years ago.
Improve this question
PLEASE HELP !!
I don't know what is going on, this piece of my stupid code does not work.
Please help me because I am a newbie to c# and I am just trying to do some code to practice.
I wrote an "If statement" and normally it should work with: {}, but it doesn't.
And there are other several problems, here is the output above the code :
main.cs(14,30): error CS1525: Unexpected symbol `{'
main.cs(17,6): error CS1525: Unexpected symbol `else'
main.cs(23,246): error CS1525: Unexpected symbol `end-of-file'
Compilation failed: 3 error(s), 0 warnings
compiler exit status 1
// this is the code
using System;
public class LOOOOOL {
public static void Main(String [] args)
{
int enterInfo;
int question1;
{
Console.WriteLine("LOOOOOL");
enterInfo = Console.ReadLine();
Console.WriteLine(enterInfo);
question1 = Console.WriteLine("Is that what you wrote ???");
if(String.Contains("y") {
Console.WriteLine("So that's cool, right ???");
}
else
{
Console.WriteLine("Can you re-write it please ???");
question1 = Console.ReadLine();
Console.WriteLine(question1);
}
}
you're missing a closing parathesis:
if(String.Contains("y")) //<---missing extra )
you have an extra bracket:
int question1;
{ //<----what's that doing there?
Console.WriteLine("LOOOOOL");
Reformatted code should look as such:
using System;
public class LOOOOOL
{
public static void Main(String [] args)
{
int enterInfo;
int question1;
Console.WriteLine("LOOOOOL");
enterInfo = Console.ReadLine();
Console.WriteLine(enterInfo);
question1 = Console.WriteLine("Is that what you wrote ???");
if(String.Contains("y"))
{
Console.WriteLine("So that's cool, right ???");
}
else
{
Console.WriteLine("Can you re-write it please ???");
question1 = Console.ReadLine();
Console.WriteLine(question1);
}
}
}
Also, your variables are int... it will never contain "y".... might want to change those two to strings
Also... String.Contains()... what string are you checking? Something for you to look into :)
Perhaps, enterInfo.Contains("y") might be userful for you.
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
I want to add the corresponding index of all the strings in the tres4 array, if they match the end of the input string. Yet, my list gets filled with all the indexes 1-12, as opposed to only those, matching the end of my input string. Only 1 should be added to my List in this case.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Encoding
{
class Program
{
static void Main(string[] args)
{
string[] tres4 = {
"CHU",
"TEL",
"OFT",
"IVA",
"EMY",
"VNB",
"POQ",
"ERI",
"CAD",
"K-A",
"IIA",
"YLO",
"PLA"
};
string message = "CHUTEL";
List<int> digits = new List<int>();
for (int i = 0; i < tres4.Length; i++)
{
if (message.EndsWith(tres4[i]));
{
digits.Add(i);
}
}
Console.WriteLine(String.Join(", ", digits));
}
}
}
You have an extra semicolon:
if (message.EndsWith(tres4[i]));
See the semicolon at the end? Remove it and it'll work.
Next time you should give a debugger a try, it would show you the problem right away.
Remove ; from if condition
if (message.EndsWith(tres4[i]))
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
I'm trying to compile this code but it gives me 2 errors about MessageBox.
It's a simple program with 3 variables. plus 2 Text boxes (box1, box2) and a button (btn).
I'm trying to add numbers in box1 with box2 and show the result as a variable named "outcome" in a Message Box.
Error 1
The best overloaded method match for
'System.Windows.MessageBox.Show(string)' has some invalid arguments
Error 2
Argument 1: cannot convert from 'method group' to 'string'
Here's the code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btn_Click(object sender, RoutedEventArgs e)
{
int str1 = int.Parse(box1.Text);
int str2 = int.Parse(box2.Text);
int outcome;
outcome = 0;
outcome = str1 + str2;
MessageBox.Show(outcome.ToString);
}
}
Change
MessageBox.Show(outcome.ToString);
to
MessageBox.Show(outcome.ToString());
Method group means the method, think of it as a function pointer. You can't print the method ToString, you want to print the resulting string and you get that by evaluating the method with ().
Try this for the first exception it's a method you miss () it's not a property
MessageBox.Show(outcome.ToString());
Typo:
use () after ToString ----> outcome.ToString()
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 am trying to use this code for NET.reflector using Reflexil. I am trying to replace code with this:
if(Input.GetKeyDown(KeyCode.Keypad5)) {
int i = 0;
Character localPlayer = PlayerClient.GetLocalPlayer().controllable.GetComponent<Character>();
foreach (UnityEngine.Object obj2 in UnityEngine.Object.FindObjectsOfType(typeof(LootableObject)))
{
if (obj2 != null)
{
i++;
LootableObject loot = (LootableObject) obj2;
Debug.Log("Loot "+i+": "+loot.transform.position.ToString());
CCMotor ccmotor = localPlayer.ccmotor;
if(ccmotor != null && tpPos1 != Vector3.zero) {
ccmotor.Teleport(loot.transform.position);
Notice.Popup("", "Teleported to "+loot.name, 1.5f);
}
break;
}
}
}
But it gives me an error when I try to compile:
Line: 1 Column: 1 Error Number: CS0116 Error Message: "A namespace does not directly contain members such as fields or methods"
This is Unity code I think. I am not that experienced. Could anyone fix this for me? Or tell me what to do? Thanks!
The snippet you're showing doesn't seem to be directly responsible for the error.
This is how you can CAUSE the error:
namespace MyNameSpace
{
int i; <-- THIS NEEDS TO BE INSIDE THE CLASS
class MyClass
{
...
}
}
If you don't immediately see what is "outside" the class, this may be due to misplaced or extra closing bracket(s) }.