C
C#17mo 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
Spekulant17mo 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
Angius17mo ago
Something not being null is unlikely to throw an error, something being null might
Spekulant
Spekulant17mo ago
Angius
Angius17mo ago
The one below is the actual error And it's quite a clear one
Spekulant
Spekulant17mo ago
can i return a list
Angius
Angius17mo ago
Sure can
Spekulant
Spekulant17mo ago
well is var numbers defined as a list
Angius
Angius17mo ago
It seems to be, yes Your method says it returns an int[] though
Spekulant
Spekulant17mo ago
oh ok that solves the error btw how long have you been coding in c#
Angius
Angius17mo ago
About 5 years or so?
Spekulant
Spekulant17mo ago
you pref the language or you have other favourites
Angius
Angius17mo ago
Yeah, C# would be my favourite. Although I quite enjoy PHP as well
Spekulant
Spekulant17mo ago
do you study or work?
Pobiega
Pobiega17mo ago
Mad man.
Angius
Angius17mo ago
I work, as a teacher
Spekulant
Spekulant17mo ago
oh nice at a uni?
Angius
Angius17mo ago
One day hopefully, technical highschool for now
Pobiega
Pobiega17mo 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
Spekulant17mo ago
do you have some recommendation how can get into c# because its hard to write code for me...
Angius
Angius17mo ago
Just making stuff tbh
Pobiega
Pobiega17mo ago
coding is all about "learn by doing"
Angius
Angius17mo ago
That's how I learned, picking random projects and googling them to completion or abandonment
Spekulant
Spekulant17mo 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
Pobiega17mo 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
Spekulant17mo 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
Pobiega17mo 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
Spekulant17mo ago
Angius
Angius17mo ago
$debug
MODiX
MODiX17mo 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
Angius17mo ago
Ah oof ouch owie my bones VS4Mac
Spekulant
Spekulant17mo ago
ye i do use mac
Pobiega
Pobiega17mo 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
Angius17mo ago
Since you're a student, do yourself a solid and get a free Rider license $freerider
MODiX
MODiX17mo 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
Pobiega17mo ago
^ Rider is excellent.
Angius
Angius17mo ago
Infinitely better than VS4Mac
Spekulant
Spekulant17mo ago
well is it that much better for writing code like im doing
Pobiega
Pobiega17mo ago
Yes 🙂
Angius
Angius17mo ago
I'd say so
Pobiega
Pobiega17mo ago
and as a student its entirely free.
Spekulant
Spekulant17mo ago
i also saw that sealion is there for writting cpp now im using xcode for it
Angius
Angius17mo ago
Yeah, CLion
Pobiega
Pobiega17mo 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
Spekulant17mo ago
but like for python i use visual studio code and not pycharm
Angius
Angius17mo ago
There's also IntelliJ for Java and Kotlin
Pobiega
Pobiega17mo ago
I use Rider for C#, IntelliJ for java, CLion for Rust
Angius
Angius17mo ago
Etc
Spekulant
Spekulant17mo 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
Angius17mo ago
Masochists and 70-year-old fossils, yes
Pobiega
Pobiega17mo ago
vim has plenty of features btw
Angius
Angius17mo ago
"Me grandaddy wrote with clay tablets and 's was good"
Pobiega
Pobiega17mo 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
Angius17mo ago
After the first gigabyte of config files Vim just turns into an ugly IDE, yeah
Pobiega
Pobiega17mo 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
Angius17mo ago
Yeah, I love how Rider points out "hey, did you know you could write it better?" lol
Spekulant
Spekulant17mo ago
well maybe it will help will see im downloading it probably in a minute
Pobiega
Pobiega17mo 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
MODiX17mo 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
Spekulant17mo 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
Pobiega17mo ago
still has the bug 🙂
Spekulant
Spekulant17mo ago
ye should i copy yours?
Pobiega
Pobiega17mo ago
nope, mine is just your old one I want you to read it and think carefully about num 🙂
Spekulant
Spekulant17mo ago
well it doesnt scream at me anymore
Pobiega
Pobiega17mo 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
Spekulant17mo ago
is it something with the order of me doing things
Pobiega
Pobiega17mo ago
nope, its related to num and specifically how it never changes value 🙂
Spekulant
Spekulant17mo 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
Pobiega17mo ago
there ya go.
Spekulant
Spekulant17mo 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
Pobiega17mo ago
loop, or string.Join I prefer string join
Spekulant
Spekulant17mo 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
Pobiega17mo ago
no there is a method called string.join that lets you turn a list into a string
Pobiega
Pobiega17mo 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
Spekulant17mo ago
@Pobiega
Spekulant
Spekulant17mo ago
do i have to install any of these
Pobiega
Pobiega17mo ago
nope
Spekulant
Spekulant17mo 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
Pobiega17mo ago
no tips and tricks other than to... use the IDE use the reference finder, use go to def, use the refactoring helper
Spekulant
Spekulant17mo 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
Pobiega17mo ago
no, Count counts you want Max
Spekulant
Spekulant17mo ago
hmm i just want to know the size of the list so the for loop knows when to end
Pobiega
Pobiega17mo ago
uhm
Spekulant
Spekulant17mo ago
i mean if there is a function max that will print max val in a list sure i will use that
Pobiega
Pobiega17mo ago
you can skip the entire loop by using Max
Spekulant
Spekulant17mo ago
okey i will do that but i would like to solve that issue also do i use count in a bad way
Pobiega
Pobiega17mo ago
well its called Count(), not count 🙂
Spekulant
Spekulant17mo ago
Console.Write(Zoznam.ZoznamImputer().Max());
Console.Write(Zoznam.ZoznamImputer().Max());
yep this line did the job
Pobiega
Pobiega17mo ago
yup
Pobiega
Pobiega17mo ago
typical things the IDE should help you with
Spekulant
Spekulant17mo 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
Pobiega17mo ago
¯\_(ツ)_/¯ if you have a using System.Collections.Generic; in the file, that should work
Spekulant
Spekulant17mo ago
well it did not hmm
Pobiega
Pobiega17mo ago
can you show your complete code?
Spekulant
Spekulant17mo 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
Pobiega17mo ago
.. do you have a using System.Linq;?
Spekulant
Spekulant17mo ago
this is my code nope
Pobiega
Pobiega17mo ago
ah, you probably are using globals remove your global includes file its messing it up for the external system
Spekulant
Spekulant17mo ago
i do not know what you talking about also how do i know what to write like using this and that
Pobiega
Pobiega17mo 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
Spekulant17mo ago
Pobiega
Pobiega17mo ago
ok, no globals.cs so rightclick the project (green icon, recodex_uloha) and click "edit .csproj"
Spekulant
Spekulant17mo ago
Pobiega
Pobiega17mo ago
remove the <ImplicitUsings> that entire line must go
Spekulant
Spekulant17mo ago
ok i did what does it do
Pobiega
Pobiega17mo ago
it adds a bunch of standard using statements to each file at compile time
Spekulant
Spekulant17mo ago
it worked
Pobiega
Pobiega17mo ago
like the ones your program was using 🙂
Spekulant
Spekulant17mo ago
ok so now i have to like manually write what im using
Pobiega
Pobiega17mo ago
yes
Spekulant
Spekulant17mo ago
at the top
Pobiega
Pobiega17mo ago
but your IDE will help you if you just type "List<" Rider will suggest to include the generic namespace same for .Max()
Spekulant
Spekulant17mo ago
Spekulant
Spekulant17mo ago
well it shows this when i delete the using linq
Pobiega
Pobiega17mo ago
you cant just write it there thou :p like, use the type in your code
Spekulant
Spekulant17mo ago
Pobiega
Pobiega17mo ago
in a valid location yes like so
Spekulant
Spekulant17mo ago
thats nice can i have more programs like Program.cs in one project
Pobiega
Pobiega17mo ago
yes and no yes, but not as you think
Spekulant
Spekulant17mo ago
Pobiega
Pobiega17mo ago
you can only have one static Main() method
Spekulant
Spekulant17mo ago
so i cant use project as a folder okey
Pobiega
Pobiega17mo ago
you can have multiple projects thou or do what I do
Pobiega
Pobiega17mo ago
Pobiega
Pobiega17mo 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
Spekulant17mo ago
oh nice
Accord
Accord17mo 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.