C
C#2y ago
Spekulant

❔ inputing numbers into list

I want to imput numbers into a list until -1 typed... and then i would like to have it as variable so i can do what ever with it
127 Replies
Spekulant
SpekulantOP2y ago
using System;

namespace recodex_uloha;
class Program
{
static void Main(string[] args)
{

}
}

class Inputer
{
public static int ReadSymbol()
{
int symbol = Console.Read();
int checker = '?';
while ((symbol < '0') || (symbol > '9'))
{

checker = symbol;
symbol = Console.Read();

}
int x = 0;

while ((symbol >= '0') && (symbol <= '9'))
{
x = 10 * x + (symbol - '0');
symbol = Console.Read();
}
if (checker == '-')
x = -x;

return x;
}
}


class Zoznam
{
static public int[] ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
Inputer.ReadSymbol();

}
return numbers;
}
using System;

namespace recodex_uloha;
class Program
{
static void Main(string[] args)
{

}
}

class Inputer
{
public static int ReadSymbol()
{
int symbol = Console.Read();
int checker = '?';
while ((symbol < '0') || (symbol > '9'))
{

checker = symbol;
symbol = Console.Read();

}
int x = 0;

while ((symbol >= '0') && (symbol <= '9'))
{
x = 10 * x + (symbol - '0');
symbol = Console.Read();
}
if (checker == '-')
x = -x;

return x;
}
}


class Zoznam
{
static public int[] ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
Inputer.ReadSymbol();

}
return numbers;
}
hello yeah im flustrated that i cant do this basic thing but i get this error that nubers is not null here
Angius
Angius2y ago
Something not being null is unlikely to throw an error, something being null might
Spekulant
SpekulantOP2y ago
Angius
Angius2y ago
The one below is the actual error And it's quite a clear one
Spekulant
SpekulantOP2y ago
can i return a list
Angius
Angius2y ago
Sure can
Spekulant
SpekulantOP2y ago
well is var numbers defined as a list
Angius
Angius2y ago
It seems to be, yes Your method says it returns an int[] though
Spekulant
SpekulantOP2y ago
oh ok that solves the error btw how long have you been coding in c#
Angius
Angius2y ago
About 5 years or so?
Spekulant
SpekulantOP2y ago
you pref the language or you have other favourites
Angius
Angius2y ago
Yeah, C# would be my favourite. Although I quite enjoy PHP as well
Spekulant
SpekulantOP2y ago
do you study or work?
Pobiega
Pobiega2y ago
Mad man.
Angius
Angius2y ago
I work, as a teacher
Spekulant
SpekulantOP2y ago
oh nice at a uni?
Angius
Angius2y ago
One day hopefully, technical highschool for now
Pobiega
Pobiega2y ago
I've been coding in C# since 2003 and tbh, these days C# is so good its hard to use another language. I keep missing some feature or the other.
Spekulant
SpekulantOP2y ago
do you have some recommendation how can get into c# because its hard to write code for me...
Angius
Angius2y ago
Just making stuff tbh
Pobiega
Pobiega2y ago
coding is all about "learn by doing"
Angius
Angius2y ago
That's how I learned, picking random projects and googling them to completion or abandonment
Spekulant
SpekulantOP2y ago
yes but im asking for help every second well i have homework that i have to code in c# thats what im doing here we have to code in c# this semester i really like python its so straight forward and the code is simple but i dont have much experience with other languages
Pobiega
Pobiega2y ago
Python is okay for small scripts. Anything larger and it gets messy. Then again, last time I did anything with a larger python project was 5+ years ago. But my day to day job involves working with 500K+ LOC projects and thats where C# really shines, imho. I do like Rust and F# thou.
Spekulant
SpekulantOP2y ago
next year i should choose subjects at uni like programming in .... i will prob look into CPP or c#,java,rust will see how can i set brake points in visual studio?
Pobiega
Pobiega2y ago
did you fix the bug in the code btw?
static public int[] ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
Inputer.ReadSymbol();

}
return numbers;
}
static public int[] ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
Inputer.ReadSymbol();

}
return numbers;
}
Spekulant
SpekulantOP2y ago
Angius
Angius2y ago
$debug
MODiX
MODiX2y ago
Tutorial: Debug C# code - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
Angius
Angius2y ago
Ah oof ouch owie my bones VS4Mac
Spekulant
SpekulantOP2y ago
ye i do use mac
Pobiega
Pobiega2y ago
VS for mac is not the same thing as VS, just so you are aware. Im sure it can debug, but its... quite a different experience over all
Angius
Angius2y ago
Since you're a student, do yourself a solid and get a free Rider license $freerider
MODiX
MODiX2y ago
There are two ways to get Rider for free: Being a student: https://www.jetbrains.com/community/education/#students Using it for an OSS project: https://www.jetbrains.com/community/opensource/#support
Pobiega
Pobiega2y ago
^ Rider is excellent.
Angius
Angius2y ago
Infinitely better than VS4Mac
Spekulant
SpekulantOP2y ago
well is it that much better for writing code like im doing
Pobiega
Pobiega2y ago
Yes 🙂
Angius
Angius2y ago
I'd say so
Pobiega
Pobiega2y ago
and as a student its entirely free.
Spekulant
SpekulantOP2y ago
i also saw that sealion is there for writting cpp now im using xcode for it
Angius
Angius2y ago
Yeah, CLion
Pobiega
Pobiega2y ago
yep, thats jetbrains C/C++ IDE the good thing about jetbrains IDEs is that they are very similar learn one, you more or less know the rest
Spekulant
SpekulantOP2y ago
but like for python i use visual studio code and not pycharm
Angius
Angius2y ago
There's also IntelliJ for Java and Kotlin
Pobiega
Pobiega2y ago
I use Rider for C#, IntelliJ for java, CLion for Rust
Angius
Angius2y ago
Etc
Spekulant
SpekulantOP2y ago
dont know it is overwhelming and i dont need that much features for my python code like im doing BFS chill pycharm. some people write much harder code in vim without the features
Angius
Angius2y ago
Masochists and 70-year-old fossils, yes
Pobiega
Pobiega2y ago
vim has plenty of features btw
Angius
Angius2y ago
"Me grandaddy wrote with clay tablets and 's was good"
Pobiega
Pobiega2y ago
it has autocomplete, debugging, language server support, project management, file browser... its just that its a fucking nightmare to setup properly 😄 ive even seen code coverage visualization in vim which is just... why?
Angius
Angius2y ago
After the first gigabyte of config files Vim just turns into an ugly IDE, yeah
Pobiega
Pobiega2y ago
yep tooling helps you write faster, and when it comes to C# specifically, autocomplete and intellisense is a godsend and some stuff, like Riders built in ReSharper, can even help you write better
Angius
Angius2y ago
Yeah, I love how Rider points out "hey, did you know you could write it better?" lol
Spekulant
SpekulantOP2y ago
well maybe it will help will see im downloading it probably in a minute
Pobiega
Pobiega2y ago
just fyi, unless you've changed it you still have a bug in
static public int[] ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
Inputer.ReadSymbol();

}
return numbers;
}
static public int[] ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
Inputer.ReadSymbol();

}
return numbers;
}
and if you want to get your hands dirty and do some projects, it wont hurt to have this list: $projects
MODiX
MODiX2y ago
Collections of application ideas that anyone can solve in any programming language to improve coding skills: https://github.com/ZacharyPatten/dotnet-console-games https://github.com/karan/Projects https://github.com/florinpop17/app-ideas
Spekulant
SpekulantOP2y ago
class Zoznam
{
static public List<int> ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
Inputer.ReadSymbol();

}
return numbers;
}
}
class Zoznam
{
static public List<int> ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
Inputer.ReadSymbol();

}
return numbers;
}
}
Pobiega
Pobiega2y ago
still has the bug 🙂
Spekulant
SpekulantOP2y ago
ye should i copy yours?
Pobiega
Pobiega2y ago
nope, mine is just your old one I want you to read it and think carefully about num 🙂
Spekulant
SpekulantOP2y ago
well it doesnt scream at me anymore
Pobiega
Pobiega2y ago
screaming is because of errors this has a bug. the IDE wont catch bugs you'll have to do that on your own 🙂
Spekulant
SpekulantOP2y ago
is it something with the order of me doing things
Pobiega
Pobiega2y ago
nope, its related to num and specifically how it never changes value 🙂
Spekulant
SpekulantOP2y ago
oh uye
class Zoznam
{
static public List<int> ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
num = Inputer.ReadSymbol();

}
return numbers;
}
class Zoznam
{
static public List<int> ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
num = Inputer.ReadSymbol();

}
return numbers;
}
Pobiega
Pobiega2y ago
there ya go.
Spekulant
SpekulantOP2y ago
also when i want to print a list do i have to do it with a for loop probably cant to console.write(numbers) thats what i did only writes stuff about the object
Pobiega
Pobiega2y ago
loop, or string.Join I prefer string join
Spekulant
SpekulantOP2y ago
what you mean about sting.join like change the list of integers into a string and then join it and print it out
Pobiega
Pobiega2y ago
no there is a method called string.join that lets you turn a list into a string
Pobiega
Pobiega2y ago
String.Join Method (System)
Concatenates the elements of a specified array or the members of a collection, using the specified separator between each element or member.
Spekulant
SpekulantOP2y ago
@Pobiega
Spekulant
SpekulantOP2y ago
do i have to install any of these
Pobiega
Pobiega2y ago
nope
Spekulant
SpekulantOP2y ago
also string.join is super nice that i dont have to do the forloop i do hate this overwhelming IDE's its like when you open adobe programs or unity they offer ton but its a lot Do you have some tips that i should use with rider the new test UI looking better tho then standart
Pobiega
Pobiega2y ago
no tips and tricks other than to... use the IDE use the reference finder, use go to def, use the refactoring helper
Spekulant
SpekulantOP2y ago
static public int MaximumNum(List<int> num_list)
{
int temp = num_list[0];
for (int i = 0; i < num_list.count(); i++)
{
if (num_list[i] > temp)
{
temp = num_list[i];
}
}

return temp;
static public int MaximumNum(List<int> num_list)
{
int temp = num_list[0];
for (int i = 0; i < num_list.count(); i++)
{
if (num_list[i] > temp)
{
temp = num_list[i];
}
}

return temp;
i thout that i could use .count() for list
Pobiega
Pobiega2y ago
no, Count counts you want Max
Spekulant
SpekulantOP2y ago
hmm i just want to know the size of the list so the for loop knows when to end
Pobiega
Pobiega2y ago
uhm
Spekulant
SpekulantOP2y ago
i mean if there is a function max that will print max val in a list sure i will use that
Pobiega
Pobiega2y ago
you can skip the entire loop by using Max
Spekulant
SpekulantOP2y ago
okey i will do that but i would like to solve that issue also do i use count in a bad way
Pobiega
Pobiega2y ago
well its called Count(), not count 🙂
Spekulant
SpekulantOP2y ago
Console.Write(Zoznam.ZoznamImputer().Max());
Console.Write(Zoznam.ZoznamImputer().Max());
yep this line did the job
Pobiega
Pobiega2y ago
yup
Pobiega
Pobiega2y ago
typical things the IDE should help you with
Spekulant
SpekulantOP2y ago
skuska.cs(43,19): error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)
skuska.cs(43,19): error CS0246: The type or namespace name 'List<>' could not be found (are you missing a using directive or an assembly reference?)
im uploading a file to a thing that runs tests on it
Pobiega
Pobiega2y ago
¯\_(ツ)_/¯ if you have a using System.Collections.Generic; in the file, that should work
Spekulant
SpekulantOP2y ago
well it did not hmm
Pobiega
Pobiega2y ago
can you show your complete code?
Spekulant
SpekulantOP2y ago
oh my bad it did
Program.cs(9,46): error CS1061: 'List<int>' does not contain a definition for 'Max' and no accessible extension method 'Max' accepting a first argument of type 'List<int>' could be found (are you missing a using directive or an assembly reference?)
Program.cs(9,46): error CS1061: 'List<int>' does not contain a definition for 'Max' and no accessible extension method 'Max' accepting a first argument of type 'List<int>' could be found (are you missing a using directive or an assembly reference?)
new error tho
using System;
using System.Collections.Generic;

namespace recodex_uloha;
class Program
{
static void Main(string[] args)
{
Console.Write(Zoznam.ZoznamImputer().Max());

}
}

class Inputer
{
public static int ReadSymbol()
{
int symbol = Console.Read();
int checker = '?';
while ((symbol < '0') || (symbol > '9'))
{

checker = symbol;
symbol = Console.Read();

}
int x = 0;

while ((symbol >= '0') && (symbol <= '9'))
{
x = 10 * x + (symbol - '0');
symbol = Console.Read();
}
if (checker == '-')
x = -x;

return x;
}
}


class Zoznam
{
static public List<int> ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
num = Inputer.ReadSymbol();

}
return numbers;
}

}
using System;
using System.Collections.Generic;

namespace recodex_uloha;
class Program
{
static void Main(string[] args)
{
Console.Write(Zoznam.ZoznamImputer().Max());

}
}

class Inputer
{
public static int ReadSymbol()
{
int symbol = Console.Read();
int checker = '?';
while ((symbol < '0') || (symbol > '9'))
{

checker = symbol;
symbol = Console.Read();

}
int x = 0;

while ((symbol >= '0') && (symbol <= '9'))
{
x = 10 * x + (symbol - '0');
symbol = Console.Read();
}
if (checker == '-')
x = -x;

return x;
}
}


class Zoznam
{
static public List<int> ZoznamImputer()
{
var numbers = new List<int>();
int num = Inputer.ReadSymbol();
while (num != -1)
{
numbers.Add(num);
num = Inputer.ReadSymbol();

}
return numbers;
}

}
Pobiega
Pobiega2y ago
.. do you have a using System.Linq;?
Spekulant
SpekulantOP2y ago
this is my code nope
Pobiega
Pobiega2y ago
ah, you probably are using globals remove your global includes file its messing it up for the external system
Spekulant
SpekulantOP2y ago
i do not know what you talking about also how do i know what to write like using this and that
Pobiega
Pobiega2y ago
the IDE should help you, but its not, because in your project its already included via a global using or implicit using show me your .csproj file and a screenshot of the solution explorer
Spekulant
SpekulantOP2y ago
Pobiega
Pobiega2y ago
ok, no globals.cs so rightclick the project (green icon, recodex_uloha) and click "edit .csproj"
Spekulant
SpekulantOP2y ago
Pobiega
Pobiega2y ago
remove the <ImplicitUsings> that entire line must go
Spekulant
SpekulantOP2y ago
ok i did what does it do
Pobiega
Pobiega2y ago
it adds a bunch of standard using statements to each file at compile time
Spekulant
SpekulantOP2y ago
it worked
Pobiega
Pobiega2y ago
like the ones your program was using 🙂
Spekulant
SpekulantOP2y ago
ok so now i have to like manually write what im using
Pobiega
Pobiega2y ago
yes
Spekulant
SpekulantOP2y ago
at the top
Pobiega
Pobiega2y ago
but your IDE will help you if you just type "List<" Rider will suggest to include the generic namespace same for .Max()
Spekulant
SpekulantOP2y ago
Spekulant
SpekulantOP2y ago
well it shows this when i delete the using linq
Pobiega
Pobiega2y ago
you cant just write it there thou :p like, use the type in your code
Spekulant
SpekulantOP2y ago
Pobiega
Pobiega2y ago
in a valid location yes like so
Spekulant
SpekulantOP2y ago
thats nice can i have more programs like Program.cs in one project
Pobiega
Pobiega2y ago
yes and no yes, but not as you think
Spekulant
SpekulantOP2y ago
Pobiega
Pobiega2y ago
you can only have one static Main() method
Spekulant
SpekulantOP2y ago
so i cant use project as a folder okey
Pobiega
Pobiega2y ago
you can have multiple projects thou or do what I do
Pobiega
Pobiega2y ago
Pobiega
Pobiega2y ago
each of those folders is a "new project" and in Program.cs all I do is "run" the project I really want so its actually just one real project, but each folder is its own contained namespace with a Program class that has a static Run method
Spekulant
SpekulantOP2y ago
oh nice
Accord
Accord2y 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