streamreader polymorfi

Status
Not open for further replies.

Realme

Active member
Joined
Jul 2, 2019
Messages
33
Programming Experience
Beginner
Hi,

I have arranged my codes in polymofi and I am currently reading textfile by using streamreader and i need to be able to sort that one ToString message shows up depending on the correct context and in sync with the streamreader.

Bellow is a small example:

C#:
 public class Konto<T>
{
           
            public T[] AnvändarID;
public int användaresidLängd;
            public int Buffert;
            public string namn;
            public string område;
            public Konto(string indatanamn, string indataområde)
{
användaresidLängd = 50;
                Buffert = 10;
                AnvändarID = new T[användaresidLängd];
namn = indatanamn;
område = indataområde;
}
        }

public class Kort<T> : Konto<T>
        {
            public T[] kortetsID;
public int kortetsIDlängd;
            public int buffer;
            public string belöning;
            public Kort(string indatanamn, string indataområde) : base(indatanamn, indataområde)
{
kortetsIDlängd = 50;
                buffer = 10;
                kortetsID = new T[kortetsIDlängd];
}
        }
        public class Dunderkatt<T> : Kort<T>
{

public Dunderkatt(string indatanamn, string indataområde) : base(indatanamn, indataområde)
{
belöning = "Dunderkatt";

}
if (File.Exists(@"C:\Users\razer\Desktop\kundlista.txt"))    // IF-stasten för att hantera filens existens i datoren innan vi gör något vidare.
                {
                    StreamReader Reader = new StreamReader(@"C:\Users\razer\Desktop\kundlista.txt", Encoding.Default, true);  // Stramreader är den metoden som används för att läsa textfilen som finns på datoren.
                    string Rad = "";
                    while ((Rad = Reader.ReadLine()) != null)     // While-Lopp finns här för att gå igenom alla rader som finns i min textfil.
                    {
                        Itemsaver.Add(Rad);   // Varje rad i textfilen sparas i en lista som ska behandlas efteråt.
                    }
                    Reader.Close();  // För att stänga av Streamreader metoden.
                    foreach (string Separera in Itemsaver) // Med foreach metoden går jag igenom alla rader som finns i Itemsaver-lista.
                    {
                        string[] Vektor = Separera.Split(new string[] { "###" }, StringSplitOptions.None); // En lista som separera ut varja rad i listan till strängvektor. 
                        VListan.Add(Vektor);
                        konto = new Konto<string>(Vektor[1], Vektor[2]); // En objekt som får den första och andra strängen i vektor-lista.
                        konto.AnvändarID[konto.Buffert] = Vektor[0];  // Den sista värdet som objekten tar emot
                        AllKonto.Add(konto);  // Alla värden som jag samlade sättas i en Konto-lista
                        
                    }
                }


How do I call correct content?

MessageBox.Show(itemSaver[0]);
 
Please post some readable code. Generally classes have an opening and closing bracket, and the same for methods. This clunk isn't even inside a method to begin with.
C#:
            if (File.Exists(@"C:\Users\razer\Desktop\kundlista.txt"))    // IF-stasten för att hantera filens existens i datoren innan vi gör något vidare.
            {
                StreamReader Reader = new StreamReader(@"C:\Users\razer\Desktop\kundlista.txt", Encoding.Default, true);  // Stramreader är den metoden som används för att läsa textfilen som finns på datoren.
                string Rad = "";
                while ((Rad = Reader.ReadLine()) != null)     // While-Lopp finns här för att gå igenom alla rader som finns i min textfil.
                {
                    Itemsaver.Add(Rad);   // Varje rad i textfilen sparas i en lista som ska behandlas efteråt.
                }
                Reader.Close();  // För att stänga av Streamreader metoden.
                foreach (string Separera in Itemsaver) // Med foreach metoden går jag igenom alla rader som finns i Itemsaver-lista.
                {
                    string[] Vektor = Separera.Split(new string[] { "###" }, StringSplitOptions.None); // En lista som separera ut varja rad i listan till strängvektor.
                    VListan.Add(Vektor);
                    konto = new Konto<string>(Vektor[1], Vektor[2]); // En objekt som får den första och andra strängen i vektor-lista.
                    konto.AnvändarID[konto.Buffert] = Vektor[0];  // Den sista värdet som objekten tar emot
                    AllKonto.Add(konto);  // Alla värden som jag samlade sättas i en Konto-lista

                }
            }
Please put some effort into your opening posts, you've already practically been kicked from one forum board for this type of stuff. And while I do understand English is not everyone's strong-point, can you please make an effort to explain what you're trying to do grammatically and in detail. There are translators out there that can translate better than what you wrote.

Since I don't understand your post, can you explain the following :
  1. What you are trying to do?
  2. What your expected outcome is with this current code?
  3. What your actual problem is with the current functionality of your code?
  4. If you are receiving any errors (As it stands its not even compilable).
  5. Please post a compilable copy of your code.
 
With a 150 IQ, and having finished a similar project, where you don't understand how to derive from classes or override tostring no mater how many times I or Skydiver explain it, I am sure that it won't be in either of our lifetimes.
 
With a 150 IQ, and having finished a similar project, where you don't understand how to derive from classes or override tostring no mater how many times I or Skydiver explain it, I am sure that it won't be in either of our lifetimes.
Since you both are off topic and can't connect the dots and write regarding the topic, it really doesn't bother me what you are sure or unsure about.
 
My better judgement here really is telling me not to procrastinate and just unwatch your topic, since I know what you're like. I don't mean to sound like I am making a personal attack, because I am not, nor would I condone such a thing on anyone, but I do need to point out a few things so that the staff and other members here know what type of person you are. You see DayGamer, or shall I call you RealME? The difference between you and the other people who come here to learn, study, get further education, and learn to write their own code, is that none of that appeals to you; even with your 150 IQ, it really should.

Myself and Skydiver have spent innumerable posts trying to explain to you (on the other dev boards you've just been run off, including Stack Overflow), how to fix the code you seek too troubleshoot. But you never make any commitment to implement the recommended changes which we suggest to you, even when we provided you with working code snippets. It just seems to go right over your head. Given your approach to learning C# is the ultimate shotgun approach. You do not know enough about the basics to teach you how to understand the code you post with and how it works. I can link to a number of posts on Dream In Code where you've flat out asked for someone else to write the code for you, and post it back to you. And I am sorry, but that's a big no no on boards like these. You need to show some effort, and desire to learn. Again, none of which seems to appeal to you.

Lastly, nor myself or Skydiver have refused to help you in the past. Quite the opposite actually. And we are not refusing to help you now, but if you want our help, you could at the very least attempt to be interested in your own code and post back what I asked you to do, because I am not going to do it for you. Nor have you even bothered your ass to explain what it is you're trying to do, and why; nor have you written it in a grammatically readable few detailed paragraphs. And I know you can do that, because your english is not as bad as you try to make out. Your opening posts are very important on forums boards like these, and if you don't put the effort into sub-sectioning your code into different snippets, and explain what each snipped is meant to do, and explain what it is not doing; and include any errors it may be causing. Well then; you will likely find a lack of interest from participating members who have more than enough potential to help you. That being said, I do advise people read his other topics on Dream In Code, before wasting your time explaining something to someone who refuses to learn the basic fundamentals of the C# language.

Please put some effort into your opening posts, you've already practically been kicked from one forum board for this type of stuff. And while I do understand English is not everyone's strong-point, can you please make an effort to explain what you're trying to do grammatically and in detail. There are translators out there that can translate better than what you wrote.

Since I don't understand your post, can you explain the following :
  1. What you are trying to do?
  2. What your expected outcome is with this current code?
  3. What your actual problem is with the current functionality of your code?
  4. If you are receiving any errors (As it stands its not even compilable).
  5. Please post a compilable copy of your code.
So whatever you decide DayGamer, you can put in the effort or you can come back under another different account. But know this, until you learn the basics of this enterprise level language, you will not succeed to understand what help you're given here today. It's counter-productive, as well as counter-intuitive for anyone here to try and help you given how little of the fundamental basics you've covered already. But sure if you want to accelerate forward on this path, lets see where it takes us.
 
My better judgement here really is telling me not to procrastinate and just unwatch your topic, since I know what you're like. I don't mean to sound like I am making a personal attack, because I am not, nor would I condone such a thing on anyone, but I do need to point out a few things so that the staff and other members here know what type of person you are. You see DayGamer, or shall I call you RealME? The difference between you and the other people who come here to learn, study, get further education, and learn to write their own code, is that none of that appeals to you; even with your 150 IQ, it really should.

Myself and Skydiver have spent innumerable posts trying to explain to you (on the other dev boards you've just been run off, including Stack Overflow), how to fix the code you seek too troubleshoot. But you never make any commitment to implement the recommended changes which we suggest to you, even when we provided you with working code snippets. It just seems to go right over your head. Given your approach to learning C# is the ultimate shotgun approach. You do not know enough about the basics to teach you how to understand the code you post with and how it works. I can link to a number of posts on Dream In Code where you've flat out asked for someone else to write the code for you, and post it back to you. And I am sorry, but that's a big no no on boards like these. You need to show some effort, and desire to learn. Again, none of which seems to appeal to you.

Lastly, nor myself or Skydiver have refused to help you in the past. Quite the opposite actually. And we are not refusing to help you now, but if you want our help, you could at the very least attempt to be interested in your own code and post back what I asked you to do, because I am not going to do it for you. Nor have you even bothered your ass to explain what it is you're trying to do, and why; nor have you written it in a grammatically readable few detailed paragraphs. And I know you can do that, because your english is not as bad as you try to make out. Your opening posts are very important on forums boards like these, and if you don't put the effort into sub-sectioning your code into different snippets, and explain what each snipped is meant to do, and explain what it is not doing; and include any errors it may be causing. Well then; you will likely find a lack of interest from participating members who have more than enough potential to help you. That being said, I do advise people read his other topics on Dream In Code, before wasting your time explaining something to someone who refuses to learn the basic fundamentals of the C# language.


So whatever you decide DayGamer, you can put in the effort or you can come back under another different account. But know this, until you learn the basics of this enterprise level language, you will not succeed to understand what help you're given here today. It's counter-productive, as well as counter-intuitive for anyone here to try and help you given how little of the fundamental basics you've covered already. But sure if you want to accelerate forward on this path, lets see where it takes us.
Okay I read some of your text as it is ollalalla alot of writing. However I do have learned alot of coding, otherwise I wouldn't have 350 lines of code in my last project.

However, I am outside right now clearing my head and when I come back I can ask the question I need help of and show the code lines. And this is my last task of C# as I am done with the courses and I am 4 days behind on my last task. I have made generic underclasses that I need help with.

This Friday I will take flight to Bulgaria so I don't have much time to wast as my new courses Php and MYSQL courses start for the next 2 month.

Also if I wasn't serious about coding I wouldn take this much courses and invest this much time in it.

And if I am unclear about statements when asking for help then oh sorry me, I am taking very intensive courses, that is gonna happen.

However, I come back soon and ask the real question if I haven't solved it on my own.
 
Hi!

I need help with getting ToString override message shown to correct user. I have saved user data and user card data. I have TCP receiver I get this user data and usercard data that I compare to and when this is in the list I want toString override to show correct message to correct user.

C#:
 try    // Try-Metod för att hantera oväntade krasch.
            {
                if (File.Exists(@"C:\Users\razer\Desktop\kundlista.txt"))    // IF-stasten för att hantera filens existens i datoren innan vi gör något vidare.
                {
                    StreamReader Reader = new StreamReader(@"C:\Users\razer\Desktop\kundlista.txt", Encoding.Default, true);  // Stramreader är den metoden som används för att läsa textfilen som finns på datoren.
                    string Rad = "";
                    while ((Rad = Reader.ReadLine()) != null)     // While-Lopp finns här för att gå igenom alla rader som finns i min textfil.
                    {
                        Itemsaver.Add(Rad);   // Varje rad i textfilen sparas i en lista som ska behandlas efteråt.
                    }
                    Reader.Close();  // För att stänga av Streamreader metoden.
                    foreach (string Separera in Itemsaver) // Med foreach metoden går jag igenom alla rader som finns i Itemsaver-lista.
                    {
                        string[] Vektor = Separera.Split(new string[] { "###" }, StringSplitOptions.None); // En lista som separera ut varja rad i listan till strängvektor. 
                        VListan.Add(Vektor);
                        //konto = new Konto<string>(Vektor[1], Vektor[2]); // En objekt som får den första och andra strängen i vektor-lista.
                        //konto.AnvändarID[konto.Buffert] = Vektor[0];  // Den sista värdet som objekten tar emot
                        //AllKonto.Add(konto);  // Alla värden som jag samlade sättas i en Konto-lista
                        
                    }
                }
                else  // Ifall filen inte hittas skrivs det här meddelandet 
                {
                    MessageBox.Show("Filen med kundars lista hittas inte. Försök igen!");
                }

Another streamreader:

try    // Try-Metod för att hantera oväntade krasch.
{
if (File.Exists(@"C:\Users\razer\Desktop\kortlista.txt")) // IF-stasten för att hantera filens existens i datoren innan vi gör något vidare.
{
StreamReader Reader = new StreamReader(@"C:\Users\razer\Desktop\kortlista.txt", Encoding.Default, true); // Stramreader är den metoden som används för att läsa textfilen som finns på datoren.
string Rad = "";
while ((Rad = Reader.ReadLine()) != null) // While-Lopp finns här för att gå igenom alla rader som finns i min textfil.
{
itemSaver.Add(Rad); // Varje rad i textfilen sparas i en lista som ska behandlas efteråt.
}
Reader.Close(); // För att stänga av Streamreader metoden.
foreach (string Separera in itemSaver) // Med foreach metoden går jag igenom alla rader som finns i Itemsaver-lista.
{
string[] Vektor = Separera.Split(new string[] { "###" }, StringSplitOptions.None); // En lista som separera ut varja rad i listan till strängvektor.
VListan2.Add(Vektor);
                       
                    }
}
else // Ifall filen inte hittas skrivs det här meddelandet
{
MessageBox.Show("Filen med Korte lista hittas inte. Försök igen!");
                }


after tcp server comes this


try
{
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
byte[] inData = new byte[256];
int antalByte = client.GetStream().Read(inData, 0, inData.Length);
richTextBox1.Text = (Encoding.Unicode.GetString(inData, 0, antalByte));
string kortIN = richTextBox1.Text.Substring(9);
                            //MessageBox.Show(Encoding.Unicode.GetString(inData, 0, antalByte));
                            Itemsaver2.Add(Encoding.Unicode.GetString(inData, 0, antalByte));
                            foreach (string Separera in Itemsaver2) // Med foreach metoden går jag igenom alla rader som finns i Itemsaver-lista.
{
string[] Vektor = Separera.Split(new string[] { "-" }, StringSplitOptions.None); // En lista som separera ut varja rad i listan till strängvektor.
                                VListan.Add(Vektor);
                               
}
for (int p = 0; p < VListan.Count; p++)
{

if (richTextBox1.Text == VListan[p][0] + "-" + VListan[p][1])
                                {
                                     MessageBox.Show(VListan[p][0]);
MessageBox.Show(VListan[p][1]);
                                   
                                    // MessageBox.Show(itemSaver[1]);
//MessageBox.Show(Tomat.ToString());
break;

                                }


Above ll I have this generic class that i need to show for correct user:


 public class Dunderkatt<T> : Kort<T>
{

public Dunderkatt(string indatanamn, string indataområde) : base(indatanamn, indataområde)
{
belöning = "Dunderkatt";

            }
            public override string ToString()
{
return "Grattis! " + namn + " Du har vunnit det exklusiva kortet" + belöning + " du kan hämta upp den i din lokala spelbutik " + område;
}
        }

There is different more but no need to show all, they have same function but different name.


Question:

What I need to declare inside "messagebox.show"  in the if state to invoke correct string override??
 
Last edited by a moderator:
Status
Not open for further replies.

Latest posts

Back
Top Bottom