No video

C# Data Access: Text Files

  Рет қаралды 267,390

IAmTimCorey

IAmTimCorey

Күн бұрын

Пікірлер: 376
@RalfsBalodis
@RalfsBalodis 3 жыл бұрын
0:00 - Intro 0:54 - Creating Demo Console App 1:39 - File path: string literal explained 2:51 - Reading from text file 5:00 - Writing to text file 7:07 - Populate DataModel fields form text file: 9:33 - • Line split 12:20 - • String interpolation 15:24 - Note on data validation when reading form text file 17:45 - Adding object to a list: 18:47 - • Anonymous instance explained 19:45 - List of DataModel to text file 23:22 - Summary and concluding remarks
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Thank you kind sir!
@juannunez3224
@juannunez3224 4 жыл бұрын
Thank you so much. The professor I have never makes us code, He always give us a power point presentation and send us home with a lab. It is nice to see someone who takes the time and explain us the code behind the theory.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Glad I could help!
@davidramirez3322
@davidramirez3322 5 жыл бұрын
Can't belive it! 80% of my work is based on text files, move it, make logs about the actions taken, update, read it to valid them, awesome Tim, you get a great way to teach. I am your Fan!! Its pure gold. Thanks so much!
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
I'm glad this video will be so useful to you.
@regal_7877
@regal_7877 3 жыл бұрын
I can't believe how helpful this actually was. I'm actually mind blown by how you managed to convey so much information and clear up a lot of my question so simply. thank you very very much. You're a blessing to humankind
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad it was helpful!
@nothingtosee8381
@nothingtosee8381 2 жыл бұрын
EXTREMELY helpful. I have been seating at my laptop for 3 hours trying to find how to read and write from text files to make a log-in interface and nothing helped me, except this beauty. Much appreciated!
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I am glad it was so helpful.
@RalfsBalodis
@RalfsBalodis 3 жыл бұрын
Reading from and writing to text files has come in very handy to me. Thank you, Tim! :) I've been doing access and security system upgrade at work for a client. Database form old system was not compatible with the new system, although it was the same manufacturer... So only option was to re-configure whole system by hand. Lucky for me, old system had a feature to print out programming as csv files. And new system could take csv in. Only problem was that text files needed to be cleaned up and needed some other work and many manipulations to be usable. Now with C# I've been flying through text files containing thousands of lines like it was nothing. Filtering, rearranging, creating new lists and other stuff. New system was ready in no time. So to speak... These basic techniques has really made my life easier. To give you some kind of reference - we don't use computer programming at work. We work with hardware. Installation and service. Electronics. To use C# at work is like using some kind of space age technology. Very exciting! One may argue, that you could use excel for working with csv... I'd say - excel is limited thou. You can't do stuff with excel like you can with C#. With C# it's freedom. Thank you!
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Thanks for the tips
@jamescaleb9676
@jamescaleb9676 6 ай бұрын
Finally a programmer with common sense who can teach! Thanks!
@IAmTimCorey
@IAmTimCorey 6 ай бұрын
You are welcome.
@mrf7283
@mrf7283 2 жыл бұрын
First of all thanks for refresher. Sometimes if you get lost in c# thing become really complicated than they should be. This is an old video but still so relevant. I just fixed some of my code after watching it. Your video never fail to deliver. I really appreciated your efforts. 👍
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@TheAngelOfDeath01
@TheAngelOfDeath01 7 жыл бұрын
Chuckles. Just keep standing on that "soapbox". The Gospel you sing is very informative and good learning! So don't give up on it, mate.
@IAmTimCorey
@IAmTimCorey 7 жыл бұрын
I'll keep preaching good development practices. Don't worry. :-)
@FerreusDeus
@FerreusDeus 3 жыл бұрын
That is the easiest and clearest I have ever seen that explained.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Thanks.
@Almethese84
@Almethese84 7 жыл бұрын
Amazing! Informative, clear and useful information! Please continue to make these great videos, I appreciate them and thank you for your time in making them!
@peterjones6733
@peterjones6733 4 жыл бұрын
Tim, that was So well explained!!! Just learning C# in past week after VBA. Storing data is key. You’ve shown me how easy this is and also to understand what’s happening. Thank You!!!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Glad it was helpful!
@mrnhaque
@mrnhaque 4 жыл бұрын
I'm struggle to build a "practising app" when learn C#, don't know how to get data to excute and then save back to. Text file absolutely is easy way. Your video help me much. Hope I've learnt more from your database turorial. Thanks.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are welcome.
@andrewthebladethrower8371
@andrewthebladethrower8371 2 жыл бұрын
thank you sir. I spent the whole day manipulating data with jugged arrays, I am giving lists a try.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@scientist100
@scientist100 4 жыл бұрын
I believe this is what Facebook used to store plain text passwords. They probably watched your video and thought, "Hey, we can save time by not hashing password in a database, it will be quick." Brilliant.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
No, Facebook doesn't store clear-text passwords.
@scientist100
@scientist100 4 жыл бұрын
@@IAmTimCorey You didn't read about it? www.theverge.com/2019/3/21/18275837/facebook-plain-text-password-storage-hundreds-millions-users
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
So that wasn't about passwords in a database. What happened was that they had a logging system that logged when certain actions happened (common). One of the log actions captured a user's password (I believe it was when it was changed but I can't remember exactly). That log was in plain text so the user's password was in it if you looked for it. They weren't storing the user's password in plain text. That was encrypted. Their logs, though, weren't. That's why security is more than just about a password or SSL. You have to think about every step along the way.
@Michael-oi5fl
@Michael-oi5fl 4 жыл бұрын
You are a godsend, sir. I love your videos. The 18 people that thumbs downed should be ashamed of themselves.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you!
@brightndiweni1657
@brightndiweni1657 6 жыл бұрын
Awesome and clean explanations especially for us beginners, wish to see more tutorial on delegates, reflection, dependency injection, rest services, more in-depth on unit testing, web api and asp.net mvc
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
I appreciate the suggestions. Unit testing videos will be coming soon, along with dependency injection for sure. The others are coming, just further back.
@fadidib8516
@fadidib8516 2 жыл бұрын
thx for the videos, I like that u go in-depth on one particular thing.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@naderbelal8439
@naderbelal8439 6 жыл бұрын
Thank you alot, that was the type of tutorial that I needed
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Excellent!
@shaynemurray6351
@shaynemurray6351 6 жыл бұрын
Thank you , your list of string method is very elegant. List processing has come of age compared to multidimensional arrays, which are fine if your a string theory physicist used to thinking in multi dimensions.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Yep, List is pretty powerful.
@jankes11ful
@jankes11ful 7 жыл бұрын
Like the way you explain things. You just got a new subscriber. Definetely will watch more!
@malcolmtucker8611
@malcolmtucker8611 7 жыл бұрын
Tim Great Video. New items make it far clearer.
@alandotchin1829
@alandotchin1829 2 жыл бұрын
Thanks Tim. Great tutorial, very clear and concise as with the rest of your tutorials. Keep up the good work!
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@eduardoliveros
@eduardoliveros 7 жыл бұрын
Nice Video Timothy! Thanks
@sallehheyat8980
@sallehheyat8980 5 жыл бұрын
timothy ? :D
@tudi6029
@tudi6029 4 жыл бұрын
Thank you! Simple and to the point, thank you very much! I just subscribed just because of this one video.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are most welcome. Thanks for watching.
@danvalrub
@danvalrub 6 жыл бұрын
Awesome video, very clear for a non-native english speaker.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
Excellent!
@exogendesign4582
@exogendesign4582 3 жыл бұрын
Damn, so its called spring interpolation now everything popped up on google, these keyword are really tricky. Thanks for the tutorial.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
I am glad it was helpful.
@Furki4_4
@Furki4_4 2 жыл бұрын
Thank you Tim, love your exposition
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@marinosanagnostou8116
@marinosanagnostou8116 7 жыл бұрын
Very good, professional work. Thank you for your effort. Please, continue .....
@IAmTimCorey
@IAmTimCorey 7 жыл бұрын
Will do.
@novaplum1617
@novaplum1617 5 жыл бұрын
No matter where I place the file, and write the file path EXACTLY as i have it structured, the compiler will not find the file and runs an exception. I cant seem to find anything about how to fix this online. EDIT: Pretty sure that it was reading the file "Test.txt" as "Test.txt.txt". When i removed the ".txt" part of the file name, the program compiled normally. I found that solution on stackoverflow and it helped out. Anyways, it was a naming problem on my end. Sorry for the mix up and thanks for the tutorials :)
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Glad you figured it out.
@nanakomastu4354
@nanakomastu4354 4 жыл бұрын
Thank u so much sir for making concepts this much simple and effective... i appreciate ur effort for these tutorials...
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are welcome.
@ThemLowkeyyBeats1
@ThemLowkeyyBeats1 4 жыл бұрын
Wow, you really know what you're doing. Great tutorial!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you!
@nawfelhamdi1551
@nawfelhamdi1551 Жыл бұрын
Thank You Tim for all your content, please can you create a tutorial about XML Serialization and Deserialization in C#
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/
@gggdrengen
@gggdrengen 5 жыл бұрын
this video helped me alot, very useful, clear and simpel information. Thanks alot Tim :)
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Awesome!
@roccos9279
@roccos9279 7 жыл бұрын
Great video Timothy! You make it so easy to understand.if you can...Could you please make a video on how to validate data in a List?Like how would you check if a new Person you are trying to add is already on the List?Thank you
@prabodamperera8049
@prabodamperera8049 6 жыл бұрын
great one.I love the way you are explaining things.Thanks
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
You are welcome.
@prabodamperera8049
@prabodamperera8049 6 жыл бұрын
I tried to implement the method to asp.net text box.But it's not working
@samstanton8655
@samstanton8655 7 жыл бұрын
This was an extremely helpful tutorial! Thank you so much for posting this!
@olivierhoule8961
@olivierhoule8961 4 жыл бұрын
One of the best tutorials ever!!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you!
@samuelbjorkqvist2282
@samuelbjorkqvist2282 4 жыл бұрын
So exceptionally great! Thanks for all your awesome videos! :D
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are most welcome. Thanks for watching.
@christopher_zhong
@christopher_zhong 7 жыл бұрын
Great video. If you can add more error handling checking, it is very helpful. Thank you!
@IAmTimCorey
@IAmTimCorey 7 жыл бұрын
When demoing a specific topic, I try to stick to that topic specifically. Otherwise it can become overwhelming to the viewer and confusing as to what is "other code" and what is code specific to the topic. I'll be doing a video specifically about error handling in the near future though.
@EwRecK1986
@EwRecK1986 8 ай бұрын
So what is the benefit or difference of using FIle.ReadAllLines, File.WriteAllLines compared to using StreamReader, StreamWriter?
@gazzolapw
@gazzolapw 3 жыл бұрын
Awesome vidio thank so much. But how do I search for specific line(person) then remove it? Thank u so much
@caedriel5555
@caedriel5555 7 жыл бұрын
Hey guys , in case you guys need the code . here it is linked below . The file name i have used is different so keep that in mind . hastebin.com/nomewuxeci.cs
@IAmTimCorey
@IAmTimCorey 7 жыл бұрын
Nice!
@Evan-zj5mt
@Evan-zj5mt 6 жыл бұрын
Hey Tim, love your videos. They've really helped me get information in and out of a file. One thing I'm unsure of though, is how to do you overwrite data after variables have been changed during an apps use? Would it just be a case of clearing the file before you save your data again?
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
The version of the save I am using overwrites the text file instead of appending to it. You can change that, though, if you want to append instead of overwriting.
@Evan-zj5mt
@Evan-zj5mt 6 жыл бұрын
Wow, quick reply. Thanks, Tim.
@tommyle4648
@tommyle4648 4 жыл бұрын
Thank you, I liked and subscribed to your channel! just what I needed to expand my knowledge
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are welcome.
@captainpotatord6984
@captainpotatord6984 3 ай бұрын
im a tad bit confused, when using file.WriteAllLines(FilePath, output); shouldnt it write all of the other person instances instead of just writting another greg
@IAmTimCorey
@IAmTimCorey 3 ай бұрын
We do, but we are overwriting the existing file, which means the file looks like we just added another Greg, when in reality we wiped out everything, rewrote everything, and added an additional entry.
@ericsimpson4513
@ericsimpson4513 5 жыл бұрын
Great video. Is this the same as serialization? It would be great if you could do a video on XML, JSON, and other types of serialization. Also, how to read and apply a configuration file. Keep up the great work!
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Not quite the same as serialization but close. More semantics than anything. Thanks for the suggestions.
@ZeroSleap
@ZeroSleap 4 жыл бұрын
Wow didnt know about interpolated strings ($"") being faster than " "+"..." Etc.This i will use in the future even for convenience and perfrmance gain.Thanks!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
It is faster to type and read. Performance-wise, it is equivalent. Sorry for the confusion.
@emaus8344
@emaus8344 2 жыл бұрын
Hello, what is the best way to extract text from PDF or Docx files?
@Rangieh
@Rangieh 5 жыл бұрын
This is nice, very informative... Thanks Tim... I just want to know if one entries has comma character, what happen if I use comma as delimeter...
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Things break. You have a couple options then. First, you could strip out commas before you insert the values into the text file (in case they aren't needed), you could change the delimiter (pipe is almost never used in normal typing or you could use a double character like two pipes), or you could account for it using double quotes. That last one is a bit trickier because you have to change how the split works. You would manually split the records but if you encountered a ," combination, you would not split on the next comma until after you saw the end double-quote symbol. This is how "real" csv files work.
@vacston
@vacston 5 жыл бұрын
You my sir are a life saver thanks :)
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
You are welcome.
@anja4883
@anja4883 3 жыл бұрын
Was the class Person declared from another file? I tried doing this code but when I typed the word Person it says "The type or namespace 'Person' could not be found"
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
If Person is a in a different namespace, you need to add a "using" statement at the top to point to the correct namespace.
@kyledawg92
@kyledawg92 3 жыл бұрын
How would you access just one variable out of the object? Like say I wanted the last name of the third person?
@mihailojovanovic2197
@mihailojovanovic2197 2 жыл бұрын
How to c# remove specific line from text file? Like i have text with Indian English Spanish French English Spanish English Polish French and i wont to remove English from a file. How to do it?
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You would have to know how to identify each line. If you can't clearly tell how to identify the line, you can't train the application to do it. Unless you have a language recognition algorithm in your application, the language itself won't be the way to do it. Are there key words that a line starts with? Is it based upon a rotating pattern where you could just remove every X lines? That's the type of thing you need to figure out and program.
@boost5207
@boost5207 2 жыл бұрын
I have a question. If i wanted to access, for example, greg jones lastname, and change it to a new lastname, or for that matter any variable, how would i achieve that? As far as i know, list have index to access, but can i make it so, that all person also has ID variable, that is stored in the text file, and use that ID to get all the content of that particular line, and then do stuff with that line person information. Hope it makes sense.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Text files cannot be used like databases. You would need to read in the file, make the change, and then write those changes back to the file. The easiest way is to read the whole file and then overwrite the whole file with the new data.
@plinioferreiradasilvaneto5471
@plinioferreiradasilvaneto5471 4 жыл бұрын
Amazing content. Thank you!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you!
@stephencarroll4171
@stephencarroll4171 Жыл бұрын
Old video but to a an old programmer updating my skills it's gold. It re-writes the file each time. Thinking of huge text files 500MB to 1GB it would probably take forever to save. Thinking of changing it to only update the changed lines, what would you recommend I research C# wise?
@khavrir35
@khavrir35 8 ай бұрын
how can i select a people type line and modify in it?
@chetanbehl388
@chetanbehl388 4 жыл бұрын
Thnx sir. Your teaching methods good. Please create a video on firebird database connectivity with c sharp
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
I will add it to the list. Thanks for the suggestion.
@scientist100
@scientist100 4 жыл бұрын
@14:33 code editor suggested: Person newPerson = new Person { FirstName = entries[0], LastName = entries[1], Url = entries[2], };
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Yep, that is a valid alternative.
@james2042
@james2042 2 жыл бұрын
I am a relatively new programmer, I have an assignment where I have to take a list of "employees" (a string of numbers) and sort them out. The strings are in a 6 digit format such as 020106, where 02 is the territory, 01 is the area and 06 is the department. I then need to take them and organize them. There is a total of 69 strings and I need a way to read them from a text file, sort them and then output as shown below (in a new text file) Any idea how I would go about doing that? Example output: Terr - 01 Area - 01 Department Number of Employees 01 1 05 15 06 3 Area - 02 Department Number of Employees 06 7 Terr - 02 Area - 01 Department Number of Employees 06 1
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I would encourage you to break down the problem into small chunks and then solve those chunks one by one. You can do it!
@fadidib8516
@fadidib8516 2 жыл бұрын
Do as the video and add sorting after that , Tim also has a video showing that.
@studentfeedback
@studentfeedback 4 жыл бұрын
Adding to a string array is difficult so you used a List Collection. But why didn't you use StringBuilder type which easily supports adding data ? Kindly answer.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
A StringBuilder works if you are doing one line. I wanted to add one line per row of data. A list is the easier way of doing that. You can use the line returns in StringBuilder but it isn't as clean.
@studentfeedback
@studentfeedback 4 жыл бұрын
@@IAmTimCorey Thanks for answering.
@caedriel5555
@caedriel5555 7 жыл бұрын
I found this tutorial pretty helpfull . In the last 3 years of me coding , i have not been able to make a High score system in the games i have worked on =)
@IAmTimCorey
@IAmTimCorey 7 жыл бұрын
Well, there you go. Now you can save your high scores.
@caedriel5555
@caedriel5555 7 жыл бұрын
Thanks ! can you possibly upload code files with comments ? this would really help the people who watch your videos .
@IAmTimCorey
@IAmTimCorey 7 жыл бұрын
Depending on the video, I do post the code but usually the code is small enough that you can follow along and re-create it for yourself. That has the added benefit of increasing your learning while providing you the code.
@caedriel5555
@caedriel5555 7 жыл бұрын
IAmTimCorey I totally agree with you there. For me I prefer to download videos & re watch them .
@mazenas3443
@mazenas3443 4 жыл бұрын
U R Amazing man ,thank u from Idlib and wish u be in All Fine thinks because U R Powerfull Teacher
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
I appreciate the kind words.
@mazenas3443
@mazenas3443 4 жыл бұрын
@@IAmTimCorey can u make video About sending Files to Email by C# ?
@shayg6072
@shayg6072 6 жыл бұрын
First of all, Thank you VERY much for your free, comprehensive videos!! I cant say how much they have helped me. I have a question that have been researching and could not find the answer for it. I have a program that generates a text file and I want to create report based on that text file. I have found Microsoft report viewer but I am not sure how to use it with my text file. I dont want to pass the whole text file to the report viewer, rather pass some parts of it and create a table out of it in my report. I would greatly appreciate any help.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
It sounds like you should create a second text file that is the one you run through report viewer so that you don't have to worry about reporting on the whole thing. As for creating a table out of the data, that's something you will have to play around with. Maybe create a CSV file and have report viewer parse it?
@shayg6072
@shayg6072 6 жыл бұрын
Thank you very much for your quick reply. Can I pass images to report viewer as well. Is there a tutorial on how to do that? Since I want to pass some images as well as the text file combined together.
@astonishscenes6579
@astonishscenes6579 3 жыл бұрын
how to read a file columnwise and to print each column to new seperate files.content of the file is Ist column is time and n number of columns .All are in float.Could u please help.
@tomthelestaff-iamtimcorey7597
@tomthelestaff-iamtimcorey7597 3 жыл бұрын
There are multiple ways to do this. I would use Regedit to parse the text line for columns but I'm an old PERL programmer.
@barnabask5321
@barnabask5321 4 жыл бұрын
ty i studied a lot
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Great!
@user-ob7ix9fd7u
@user-ob7ix9fd7u 3 жыл бұрын
Thank you! Very helpful tutorial
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad it was helpful!
@TonyDaExpert
@TonyDaExpert 3 жыл бұрын
This is what I needed thanks!
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
Glad I could help!
@stanleypaseur2553
@stanleypaseur2553 3 жыл бұрын
very useful. However my output file will be hundreds of lines long. Reading it in as a list, adding one line and then writing it out will take up too much time. I need to just append/add to the file by adding a new line. Any thoughts?
@sleepymarauder4178
@sleepymarauder4178 5 жыл бұрын
Clear explanation. Subbed
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Thanks!
@ThrashAbaddon
@ThrashAbaddon 7 жыл бұрын
thank you :)
@automatykarobotyka2333
@automatykarobotyka2333 4 жыл бұрын
Great video, clear explain.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you!
@hadeseye2297
@hadeseye2297 6 жыл бұрын
Very informative. Thanks.
@IAmTimCorey
@IAmTimCorey 6 жыл бұрын
You are welcome.
@bonjonbovi-
@bonjonbovi- 2 жыл бұрын
can I also access one line? for example FirstName from line 2?
@blackbarry45
@blackbarry45 4 жыл бұрын
wait, why object person can be defined more than once ? is it disappearing (deleting itself) ?
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Think of a class as a blueprint for a house. When you instantiate the class, you create a new house based upon the blueprint. You can create many houses that look the same because you used the same blueprint, yet each house can hold different things inside. Variables that hold these housed (called class instances) just remember the address to the house. You can pass that address around but you aren't making a copy of the house, you are just copying the address. Does that help?
@blackbarry45
@blackbarry45 4 жыл бұрын
@@IAmTimCorey I think I got it. Thank you
@ariellopezcavazos472
@ariellopezcavazos472 3 жыл бұрын
Great tutorial !!. Thank you so much Sr.
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
You are welcome!
@BoilermakerRV
@BoilermakerRV 4 жыл бұрын
I'm curious what you would recommend if one wanted their application to save individual files in the same manner as Excel with .xlsx, Word with .docx or Acrobat with .pdf. I believe some of these formats are simply XML documents, which is just a fancy text file, is it not? I'm currently looking at using JSON to create my "own" file format. Wondering if you have thoughts and/or suggestions for this approach. As always, thanks!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
I would recommend using a tool to build those formats. You technically could create them but it would be a LOT of work. Writing to the file is the simple part. Knowing what to write is the hard part.
@wisbenah
@wisbenah 7 жыл бұрын
Thanks for the video... Nice presentation.
@davidnewell7242
@davidnewell7242 2 жыл бұрын
So tim with vs 2022 and .net when i ,while in project, right click, just how you did, and add class in the class. I get all the using stuff
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
It isn't a bug. The "using stuff" doesn't negatively impact your application.
@AdrianRoix
@AdrianRoix Жыл бұрын
Hi Tim, Thank you for your videos. What happens when a new object is created in a for/foreach loop? Is the first object reused? If not, then on a larger scale could creating objects in for/foreach loops produce clutter in the program, and what could be done to avoid that? The first thing I think of is creating a placeholder instance of an object outside of a loop that the can be accessed, using it to hold temporary values. It also dawned on me to possibly add a number at the end of each instance being created within the loop so each instance has a unique name. Am I over thinking this? I would like to know how this is functioning on as low-level as I can.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
In a foreach loop, the variable is getting re-initialized in every iteration. The old data is discarded and the garbage collector will clean it up. However, if you are iterating over objects (like class instances), you aren't actually duplicating the class, just the location of the class (super-efficient). No, there is rarely a case where you need to optimize a foreach loop because of the variable. I can't remember an instance where I've needed to do that. The placeholder wouldn't solve anything because it would end up doing the same exact work. Adding a number to the variable name? No, you couldn't do that and it wouldn't be valuable to do. In fact, it would be terribly inefficient. The variable only lives for one iteration of the loop. In your mechanism, it would actually last longer (in theory).
@AdrianRoix
@AdrianRoix Жыл бұрын
@@IAmTimCorey I came across the term garbage collector somewhere but I haven't really thought I should look into it until now. I appreciate you clearing up some of my speculation (though there will always be more) with your response. Thank you for your time and service. Subscribed!
@unknownidentity3824
@unknownidentity3824 3 жыл бұрын
This is easy and all i knew all this stuff before the video... But how do you read a different kind of data in a separate lines e.g. when you got a text for several lines and then an array. How do you sort that kind of information because parts[0], parts[1] etc is not going to work anymore. Also how to store delimiters to a result file aswell?
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
You need to write the logic to parse it yourself. Or you can save it in a known format like JSON and then have a pre-built parser do the work for you.
@theresaposey
@theresaposey 4 жыл бұрын
awesome teacher thank u
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
You are welcome.
@Blackener
@Blackener 5 жыл бұрын
"Assuming is the mother of all problems when it comes to programming" -The best quote of all times
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
It is one of Tim’s Software Development Commandments. The next is “Don’t trust the user”.
@7SOON_2003
@7SOON_2003 4 жыл бұрын
There is a .txt file with many variables in it, and I want to display the value itself but when I do this it displays the whole line. Any tips? Cheers.
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
It sounds like you need to parse the data in the line. You get the whole line, now pull out just the piece you need.
@galerians3
@galerians3 5 жыл бұрын
Hello, Tim! First of all, thank you for this video, it really helped me out a lot on a project i'm working on. I have a question though. I want to be able to search for the first element in the file and have the program return the rest of the line to me. Here is an example - Die: 747 measurement: 266.7 Notes: Some sample note here. Something like this but I want to search by die, in other words, the first element. Thanks in advance. Best of luck to you.
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
Load all of the lines into an array and then just do a search on each one for the starter text.
@galerians3
@galerians3 5 жыл бұрын
@@IAmTimCorey Ok, thank you. I'll try that. I'm also having a really hard time using this code in a try catch block and at the same time creating the file. Any suggestions?
@DD-ed9rd
@DD-ed9rd 4 жыл бұрын
Hi. Got a question here. I am really new to C# 1) I am only trying to read 1 line[Age and Gender], Can I still follow the steps? 2) How do I use the age data from textfile instead of writing it myself int gender = 0; int Age=32;
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Yes, you can read one line, although it is easiest to read all of the lines and get the data for the first line from that list. As for your code, I am not sure what you are asking.
@RiteshSookun
@RiteshSookun 5 жыл бұрын
Hi, nice video. Just a quick question - is there a way to print to the console only one list item (eg. line 9 in the FirstName list)?
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
I'm not sure I understand the question. Yes, you get to choose what you print to the console. You can print just one object or even just one part of one object to the console.
@markdonner25-06
@markdonner25-06 Жыл бұрын
It is possible to read the files from one folder and write them to another folder?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Sure!
@gregsonnawahin6251
@gregsonnawahin6251 3 жыл бұрын
very impressive and outstanding explanation Can i ask is this can be used as data base from that text file?
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
You could use this in place of a full database if it is a small enough application. If it gets too big, it would be too fragile.
@kutloranno2325
@kutloranno2325 3 жыл бұрын
I do not know if you are ever gonna be able to see this comment. but I did this in windows forms to remove a line from a text file after a person pays their loans(I used the remove method). Then it threw an exception saying invalid operation:collection was modified. But it did act like I want to act it removed the line from the text file . So your technique worked greatly and thank you for that. but my problem in the exception . How do I stop it from doing the exception? Anyone can help if they understand please
@IAmTimCorey
@IAmTimCorey 3 жыл бұрын
When you are looping over a set and you change the set, it causes problems. Ideally, you pull the row out later. Another option is to do a for loop backwards (start at the end and work back to zero).
@kutloranno2325
@kutloranno2325 3 жыл бұрын
@@IAmTimCorey Thank you very much Tim Corey I was able to fix the issue by creating a for loop backwards just like you said. Appreciate
@ZiaurRahmanAdvocate
@ZiaurRahmanAdvocate 4 жыл бұрын
good presentation
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Thank you!
@bradfeigenbaum5227
@bradfeigenbaum5227 5 жыл бұрын
Hi Tim, what if two fields in the text file are numbers and you wanted to calculate the sum of the two numbers in a new field then output that into the same text file?
@IAmTimCorey
@IAmTimCorey 5 жыл бұрын
I'm not sure what the question is. Yes, you can do that. You just need to build the logic to do so.
@christophfrenzel6859
@christophfrenzel6859 4 жыл бұрын
Hey Tim, what's the difference between using a streamwriter/reader or just simply using File.(...) ? Both can achieve the same thing. And thanks for the videos, great help!
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Depends which type of method you are using with File but it can just be simplicity.
@pauljekyll3508
@pauljekyll3508 4 жыл бұрын
When creating csv files, do I need to avoid strings that have a comma in them? Or is there a trick to it?
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
Avoiding commas is the easiest thing to do. Another option is to change the delimiter from comma to something even less used like a pipe character (|). You can also escape the comma by changing it to a different value and then changing it back. The official CSV format allows commas by putting strings inside quotes but this makes it a bit more difficult to work with in C# without a library.
@JoshyHJoshy
@JoshyHJoshy 7 жыл бұрын
Dear Timothy, I had to use the following syntax for displaying people using foreach loop, since my VS2010 does not support the $ format: Console.WriteLine( "{0} {1} {2}", person.FirstName, person.LastName, person.URL ); However, trying to use the same format for writing the fields back to the file as a single string confuses me: output.Add( "{0},{1},{2}", person.FirstName, person.LastName, person.URL ); This doesn't work, as Add takes one argument, and not four. output.Add("{person.FirstName},{person.LastName},{person.URL}"); This doesn't work either, as the same literal strings get written back to the file. I wonder if you could please help me figure out what to do here? Thanks
@JoshyHJoshy
@JoshyHJoshy 7 жыл бұрын
Thank you very much indeed.
@quangthienbui3608
@quangthienbui3608 4 жыл бұрын
Dear Tim Corey, Is there any way to insert a string into a specific row location of a .csv file? (e.g. I want to insert a string to the second row of a CSV file which has 10 rows data)
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
The easiest thing to do would be to read all of the lines and then do the insert in your List in C# and then write all of the lines.
@quangthienbui3608
@quangthienbui3608 4 жыл бұрын
​@@IAmTimCorey but my csv file is pretty big (maybe over 10.000 lines), and I just want to modify the second line of it. It's a bit risky if I change all the content of the file just to modify a single line.
@aco83r
@aco83r 7 жыл бұрын
Thanks for this video. I have problem here> I am using a Visual Studio 2012. When i type: Console.WriteLine($"{person.FirstName} {person.LastName}: {person.Url}"); i get error: Unenspected character '$' If i change to: Console.WriteLine(person.FirstName +""+ person.LastName+":"+person.Url); it is works. What is the problem? version VS2012 or something else ? Sorry, english is not my native language. Best regards
@IAmTimCorey
@IAmTimCorey 7 жыл бұрын
Yep, the issue is Visual Studio 2012. String Interpolation (using the $) was introduced in C# 6.0 (Visual Studio 2015). If you are stuck using Visual Studio 2012, you will need to either do what you figured out (which isn't very efficient so don't do it in a loop) or you could use the string.Format method (which is built right into Console.WriteLine or you can call it manually at any other point). Your line would then look like this: Console.WriteLine("{0} {1}: {2}", person.FirstName, person.LastName, person.Url); However, if you aren't restricted by your company or the age of your computer, go to www.VisualStudio.com and download Visual Studio 2017 Community Edition. It is free and it will give you all the new features available in C# 6.0 and C# 7.0 as well as all the improvements to the tooling.
@wilmararias2083
@wilmararias2083 6 жыл бұрын
Use person.FirstName.Tostring() ect ...
@MrBan001
@MrBan001 4 жыл бұрын
i've used a switch case... it worked not sure if it is the best solution tho. Felt a little clunky
@IAmTimCorey
@IAmTimCorey 4 жыл бұрын
The fact that it worked is a big deal. I always say that is the most important thing in an application. The fact that it bothers you and you are still wondering if there was a better way is great. It will push you to keep learning and improving. Your code will never be perfect but constant evaluation and improvement will ensure that your code gets better and better.
@cruzli2656
@cruzli2656 2 жыл бұрын
How about exporting data to template text file and overwrtie it using this
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You can do that.
File, FileStream, StreamWriter, and StreamReader | Coding in C#
28:02
The Cynical Philosopher
Рет қаралды 3,3 М.
Learn Any Programming Language In 3 Hours!
22:37
Code With Huw
Рет қаралды 351 М.
7 Days Stranded In A Cave
17:59
MrBeast
Рет қаралды 94 МЛН
Schoolboy Runaway в реальной жизни🤣@onLI_gAmeS
00:31
МишАня
Рет қаралды 3,9 МЛН
Working With The File System in C# - Managing Folders and Files
35:07
C# Read and Write to a Text File
7:09
Programming w/ Professor Sluiter
Рет қаралды 120 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 354 М.
If __name__ == "__main__" for Python Developers
8:47
Python Simplified
Рет қаралды 398 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 155 М.
how Google writes gorgeous C++
7:40
Low Level Learning
Рет қаралды 859 М.
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 933 М.
Generating Fake Data in C# with Bogus
36:11
IAmTimCorey
Рет қаралды 22 М.
Read and Write files in 10 minutes | C#
9:26
tutorialsEU
Рет қаралды 37 М.