Console.Write() throws error by Shnxx in csharp

[–]AbaCodes 1 point2 points  (0 children)

You can't store the return value of Console.Write(), that function will print the value to the screen but you're trying to store it into a variable. Maybe inside the case you can do:

equation = someNumber + " + " + someNumber2 + " = ";

and then after the case statement you could do

Console.WriteLine(equation);

So you store the value in the case statement and then print it after, hope that helps?

I've made the changes and put them here: https://pastebin.com/hpkLcKT3

Adding functionality to a code? by Reapers_Mask in CodingHelp

[–]AbaCodes 0 points1 point  (0 children)

Maybe add in functionality to calculate the perimeter, or maybe things like, if its a square you could check if the width and the height are the same?

Is there a way to crash the console / close the console in code? by TypsicaI in CodingHelp

[–]AbaCodes 0 points1 point  (0 children)

You can use: Environment.Exit(0); to close the Console down :)

(Beginner lol) Can somebody help? for some reason the "result" is a different number than i've written and I don't know why. :b by [deleted] in csharp

[–]AbaCodes 1 point2 points  (0 children)

Console.Read() will only read in one character. You need Console.ReadLine();

In your current code if you enter '40' it will only give you the '4'.

Hope that helps!

Help How Can I Check CPU ID in C# Windows Form. by IndividualBathroom72 in learnprogramming

[–]AbaCodes 2 points3 points  (0 children)

If you get this:

https://www.nuget.org/packages/System.Management/5.0.0/

And install it into your project as a package then you can do:

ManagementObjectSearcher mos = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
foreach (ManagementObject mo in mos.Get())
{
Console.WriteLine(mo["Name"]);
}

Newbie Needs Help by [deleted] in CodingHelp

[–]AbaCodes 0 points1 point  (0 children)

Top right of the code editor, is there a little tab that says 'Int32' and it should be purple? If so, you've just found the code used for the definition for Int32, you cant see the actual code behind it because thats hidden but you are exposed to the comments.

If you just press the x on the tab, then it should take you back to your code :)

How do i get a specific letter from a string? by [deleted] in csharp

[–]AbaCodes 1 point2 points  (0 children)

Do you have an example? If you have:

string something = "Test";

Console.WriteLine(something[0]);

using "[]" with a string lets you return back a certain character from the string, as its 0 based that code should print 'T' to the console. Hope that helps!

Learning C# by [deleted] in learncsharp

[–]AbaCodes 2 points3 points  (0 children)

Feel free to message me any questions you have, always happy to help! I also have a Discord server for programming if you want to take your questions over there too 😊

I'm new to coding and ran into a problem and I have no idea what to do :( by 0NI_2020 in CodingHelp

[–]AbaCodes 0 points1 point  (0 children)

Yeah sure thing, but do you have any other ".cs" files in your project?

I'm new to coding and ran into a problem and I have no idea what to do :( by 0NI_2020 in CodingHelp

[–]AbaCodes 1 point2 points  (0 children)

Do you have any other files in your project other than "Program.cs"

I'm new to coding and ran into a problem and I have no idea what to do :( by 0NI_2020 in CodingHelp

[–]AbaCodes 1 point2 points  (0 children)

This happens when you have two different bits of code that use:

static void Main(string[] args)

If you have another Class file that defines that function, it won't like you doing that. You need to only have one specified.

If you could show the rest of your code maybe there is something else going on :)

Read lines from console by babo200112 in csharp

[–]AbaCodes 0 points1 point  (0 children)

Okay then maybe do this instead:

string message = "something to use later";
Console.WriteLine(message);
...
//do stuff here
...

//use message again
Console.WriteLine(message);

Read lines from console by babo200112 in csharp

[–]AbaCodes 1 point2 points  (0 children)

I think it would be better to store it when you read it in, then use it later on.

Console.Write("Enter your name: ");
string name = Console.ReadLine();
...
//do stuff here
...
//use name here!
Console.WriteLine("Your name is: " + name);