C
C#12mo ago
Masimos

❔ Do not know why this does not work

Going trough a 2 yeat old online C# course and do not know what is up with this.
26 Replies
Masimos
Masimos12mo ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace Coding_Giants_Lesson_12_Metode
{
class Program
{
//main je metoda koja se poziva uvjek poziva pri startu
static void Main(string[]args)
{

SayHello(); // < -ovo je poziv metode bez parametara!
SayHelloToSomeone("Petar");
SayHelloToSomeone("Marko");
SayHelloToSomeone("Maksim");

Console.ReadKey();
}
// [modifier] - mijenja pristup i ponasanje
// [returnType] odredjuje vrstu podataka koji metoda vraca (ako odredite return type MORATE vratit taj return type), void zr
// [lista Argumenata) - vrijednosti koje mi mozemo proslijediti nasoj funckiji

// anatomija metode
// [modifier] [returnType] imeFunkcije/Metode([Lista argumenata])

//pristup metodi(public i private)
//PUBLIC:metodi mozemo pristupiti iz bilo kojeg dijela app
//PRIVATE:mozemo pristupiti samo iz jedne i samo jedne klase(!)

static void SayHello() // <- prazna zagrada od listeArgumenata znaci da ne trazi argumente (ali svakako morate stavit zagrade)
{
Console.WriteLine("HENLO");
}
static void SayHelloToSomeone(string name) // <- name je ARGUMENT vrste string koji mi mozeno koristiti u metodi
{
Console.WriteLine("HENLO {O}!",name);
}


}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace Coding_Giants_Lesson_12_Metode
{
class Program
{
//main je metoda koja se poziva uvjek poziva pri startu
static void Main(string[]args)
{

SayHello(); // < -ovo je poziv metode bez parametara!
SayHelloToSomeone("Petar");
SayHelloToSomeone("Marko");
SayHelloToSomeone("Maksim");

Console.ReadKey();
}
// [modifier] - mijenja pristup i ponasanje
// [returnType] odredjuje vrstu podataka koji metoda vraca (ako odredite return type MORATE vratit taj return type), void zr
// [lista Argumenata) - vrijednosti koje mi mozemo proslijediti nasoj funckiji

// anatomija metode
// [modifier] [returnType] imeFunkcije/Metode([Lista argumenata])

//pristup metodi(public i private)
//PUBLIC:metodi mozemo pristupiti iz bilo kojeg dijela app
//PRIVATE:mozemo pristupiti samo iz jedne i samo jedne klase(!)

static void SayHello() // <- prazna zagrada od listeArgumenata znaci da ne trazi argumente (ali svakako morate stavit zagrade)
{
Console.WriteLine("HENLO");
}
static void SayHelloToSomeone(string name) // <- name je ARGUMENT vrste string koji mi mozeno koristiti u metodi
{
Console.WriteLine("HENLO {O}!",name);
}


}
}
MODiX
MODiX12mo ago
TheRanger
REPL Result: Failure
Console.WriteLine("HENLO {O}!","test");
Console.WriteLine("HENLO {O}!","test");
Exception: FormatException
- Input string was not in a correct format.
- Input string was not in a correct format.
Compile: 317.823ms | Execution: 27.416ms | React with ❌ to remove this embed.
TheRanger
TheRanger12mo ago
well, we commonly use string interpolation anyway
MODiX
MODiX12mo ago
TheRanger
REPL Result: Success
string name = "test";
Console.WriteLine($"HENLO {name}!");
string name = "test";
Console.WriteLine($"HENLO {name}!");
Console Output
HENLO test!
HENLO test!
Compile: 520.146ms | Execution: 74.863ms | React with ❌ to remove this embed.
TheRanger
TheRanger12mo ago
i see ur issue anyway you wrote O not 0
O // this is an O
0 // this is a 0
O // this is an O
0 // this is a 0
Masimos
Masimos12mo ago
how did i do Smadge is string interpolation anyways?
TheRanger
TheRanger12mo ago
heres an example
MODiX
MODiX12mo ago
TheRanger
REPL Result: Success
string name = "test";
Console.WriteLine("HENLO {name}!");
Console.WriteLine($"HENLO {name}!");
string name = "test";
Console.WriteLine("HENLO {name}!");
Console.WriteLine($"HENLO {name}!");
Console Output
HENLO {name}!
HENLO test!
HENLO {name}!
HENLO test!
Compile: 628.601ms | Execution: 73.520ms | React with ❌ to remove this embed.
TheRanger
TheRanger12mo ago
basically it converts the variable in between {} into its value you'd need to put $ before the first quotation of the string in order to activate it, just like in the example
Masimos
Masimos12mo ago
and what is the difrence between that and
Console.Writline("Henlo{0}",name)
Console.Writline("Henlo{0}",name)
ero
ero12mo ago
It's shorter and can be used anywhere in any string $interpolation
MODiX
MODiX12mo ago
String interpolation is the preferred way of building strings in C#. It is easier to read than concatenation. For example:
var foo = 1;
var bar = 2;
Console.WriteLine("foo is equal to: " + foo + " and bar is equal to: " + bar);
var foo = 1;
var bar = 2;
Console.WriteLine("foo is equal to: " + foo + " and bar is equal to: " + bar);
can be written as:
var foo = 1;
var bar = 2;
Console.WriteLine($"foo is equal to: {foo} and bar is equal to: {bar}");
var foo = 1;
var bar = 2;
Console.WriteLine($"foo is equal to: {foo} and bar is equal to: {bar}");
Masimos
Masimos12mo ago
👍
TheRanger
TheRanger12mo ago
and more readable
ero
ero12mo ago
Also more performant actually
Masimos
Masimos12mo ago
how do you use the modx bot
TheRanger
TheRanger12mo ago
$eval
MODiX
MODiX12mo ago
To compile C# code in Discord, use !eval Example:
!eval for(int i = 0; i < 4; i++) Console.WriteLine(i);
!eval for(int i = 0; i < 4; i++) Console.WriteLine(i);
Please don't try breaking the REPL service. Also, remember to do so in #bot-spam!
TheRanger
TheRanger12mo ago
!e also works
Masimos
Masimos12mo ago
!e
TheRanger
TheRanger12mo ago
read the example u need to provide code
Masimos
Masimos12mo ago
ohh and can you see the output anyvere
TheRanger
TheRanger12mo ago
what do you mean?
Masimos
Masimos12mo ago
like start that code and see the output here
TheRanger
TheRanger12mo ago
it outputs at where you executed the code so if you ran your code here, it will output here if your trying to display the output into a different server, i dont think it will work
Accord
Accord12mo ago
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.
Want results from more Discord servers?
Add your server
More Posts