• Advertisement
  • entries
  • comments
  • views

C# (here we go...)

Sign in to follow this  


Downloaded Visual C# and have started trying to learn it. The actual visual aspects of designing Windows Forms stuff and so on is very easy but it is the C# stuff I'm struggling with.

Here is the code I've been playing with to load a text file into a TextBox control (don't laugh - I've only been doing C# for twenty five minutes)

private void openToolStripMenuItem_Click(object sender, EventArgs e)
if (OpenDialog.ShowDialog() == DialogResult.OK)
String[] Temp = TextBox.Lines;

using(StreamReader S=new StreamReader(OpenDialog.OpenFile()))
String line; int N=0;

Array.Resize(ref Temp, N + 1);
Temp[N] = line;
N = N + 1;

TextBox.Lines = Temp;

Help! I've got no idea what I'm doing!

Do you lot reckon I'd be better to start off with some C# console applications until I'm comfortable with the language? Will the Windows Forms stuff make a bit more sense?

I reckon from a few recent conversations that if I can learn C# fairly quickly, there may be quite a lot of work round my way in programming. I'm sick and tired of sales and want to write programs for a living now.

Anyone got any good links to C# tutorials as well? I haven't really looked myself yet but I'd like to know which ones you lot recommend.

Sign in to follow this  


Recommended Comments

Hey, nice to see you're going for it :-)

Sorry, I can't help much with the actual code. It looks fine to me but then I haven't done much text stuff with C# yet. However, I reckon you should be able to dump the file into a string in one go... In any case, the best examples and documentation I found (was pointed to) came with Visual Studio itself. Press F1. I found the class libraries pretty good.

Share this comment

Link to comment
I thought so too, but when I tried to assign to the TextBox.Text property, I couldn't get newlines to work. Adding "\n" at the end of the string put a weird control character in and "\0" was just ignored.

I tried to call Array.Resize on the TextBox.Lines property but it told me I couldn't call that on a property.

It is all very confusing for a poor old C++ programmer.

I agree the docs are pretty good. I'm working through the basics in console mode at the moment until I've got my head round the language a bit more. It feels really weird learning a new language but I reckon if I'm ever going to get into earning any money at what I spend so much of my life doing anyway (which has got to be good), I really need all this .NET stuff.

As far as I can see, C# is coming big-style and you can either jump on board or get swept away forever.

Share this comment

Link to comment
You can do that really simply by just using ReadToEnd():

public void LoadFile(String Filename)
StreamReader Reader = new StreamReader(Filename);
TextBox.Text = Reader.ReadToEnd();

Are you sure that you've enabled MultiLine and/or AcceptsReturn?

Good luck!

Share this comment

Link to comment
Aha. Cheers for that, programmer16. I thought you'd probably post a simple answer based off some previous conversations.

No idea about Multiline or Accept Returns. All very new to me. I'll have a look tonight.

I'm actually working on console apps for now. I'm going to try to write a text adventure to get a feel for the language before I look at Windows Forms stuff in detail.

Cheers for the tip.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement