mono tutorial code for examples in LXF

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

mono tutorial code for examples in LXF

Postby lis » Thu Dec 28, 2006 12:06 pm

Hi there,

I thought it might be a good idea to post the code of the examples Paul gives, and that are not on the DVD, ... since I spent hours trying to find what went wrong,
installing and uninstalling distro A and distro B, package C,D,E and F etc etc,
when in the end I had just forgotten to put the added code in braces :shock:

So to help others save some time, by showing them the code that actually works, I'm posting it here.


Code: Select all
// project created on 12/27/2006 at 2:35 PM
using System;
using System.IO;

namespace inputOutput
{
   class inputOutput
   {
      public static void Main(string[] args)
      {
      string myIOfile = File.ReadAllText("myIOfile.txt");
      Console.Write(myIOfile);
         
      }
   }
}



That's all for the first example in LXF 88.
greetz,
Lis
User avatar
lis
 
Posts: 57
Joined: Thu Nov 30, 2006 1:50 pm
Location: Noord Holland, the Netherlands

Postby lis » Thu Dec 28, 2006 6:26 pm

Here's another one.
Don't make the textfiles with "touch" & leave them empty ;-)


Code: Select all
// project created on 12/28/2006 at 5:13 PM
// This app. reads the contents of certain files in a given directory,
// and writes all its contents to screen.

using System;
using System.IO; 

namespace forEachLoop
{
   class forEachLoop
   {
      public static void Main(string[] args)
      {
         string[] files = Directory.GetFiles("/home/lis/Documents");
         foreach (string file in files)
         {
            if(file.EndsWith(".txt"))
            {
            Console.Write(File.ReadAllText(file));
            }
         }
      }
   }
}


:D

I'm enjoying this
:-D
User avatar
lis
 
Posts: 57
Joined: Thu Nov 30, 2006 1:50 pm
Location: Noord Holland, the Netherlands

Postby lis » Thu Dec 28, 2006 6:48 pm

I tried some stuff from the information Paul gave with the mono tutorial in LXF 88.

Code: Select all
// project created on 12/28/2006 at 4:20 PM
using System;
using System.IO; 

namespace conditionalStatementsAndLoops
{
   class conditionalStatementsAndLoops
   {
      public static void Main(string[] args)
      {
         string conditie = File.ReadAllText("conditie.txt");
         conditie += "\nHey .. With this ONE program I'm sending output in two directions; part of it lands in a file and another part to screen .. Kewl !";
         File.WriteAllText("conditie.txt", conditie);
         Console.Write(conditie);
         Console.WriteLine("\n");
         for (int i = 1; i <= 16; ++i)
         {
            Console.WriteLine("Thunder..");
           }
           Console.WriteLine("Thundercats ! HO !\n");
           Console.WriteLine("But this gooblygoock is not being written to the file conditie.txt terecht :-) !");
      }
   }
}


Sorry !! I could not resist trying it and posting it !!
Must be getting addicted 8)
User avatar
lis
 
Posts: 57
Joined: Thu Nov 30, 2006 1:50 pm
Location: Noord Holland, the Netherlands

Postby bren7x64 » Wed Jan 03, 2007 1:01 pm

Not specifically in reply to your posts, but, I am a long-time M$ hater and I cannot believe that anything out of Redmond is worth anything - having seen the ease with which one can accomplish things in C#, I have to re-evaluate my position ... - DAMN - I HATE having to think again ... ;-)
bren7x64
 
Posts: 7
Joined: Thu Jul 14, 2005 2:51 pm

Postby TonyLB » Wed Jan 03, 2007 7:44 pm

Some of the stuff in C# is great. You can see that it has progressed from both Java and C++ (I love the @ to make strings literal between the start and end quotes, no escaping). But others really suck and you wonder why they didn't stick with the Java way of doing things.

Tony
In the beginning was nothing, which exploded! (Lords and Ladies, Terry Pratchett)
TonyLB
LXF regular
 
Posts: 112
Joined: Tue Apr 12, 2005 7:08 pm
Location: Wirral, UK

System.IO.File does not contain a definition for ReadAllText

Postby zmsc1 » Sat Jan 06, 2007 8:41 am

Hi, I'm trying the code you posted, but it won't compile, giving error message 'System.IO.File' does not contain a definition for ReadAllText. As this is my first ever bit of C#, I seem to be stuck pretty early on!

Any pointers appreciated.

Stuart
zmsc1
 
Posts: 10
Joined: Tue Jan 24, 2006 8:04 pm

RE: System.IO.File does not contain a definition for ReadAll

Postby jjmac » Sat Jan 06, 2007 9:37 am

TonyLB wrote:

>>
you wonder why they didn't stick with the Java way of doing things.
>>

I think they may well have had there reasons :evil: :evil:


jm
http://counter.li.org
#313537

The FVWM wm -=- www.fvwm.org -=-

Somebody stole my air guitar, It happened just the other day,
But it's ok, 'cause i've got a spare ...
jjmac
LXF regular
 
Posts: 1996
Joined: Fri Apr 08, 2005 1:32 am
Location: Sydney, Australia

Postby lis » Sun Jan 07, 2007 10:15 am

Hi Stuart,

The error message you mention, is what gets returned to you when you forgot to set Monodevelop's configuration to save the executable files in the same directory as the project.

Check issue 88, monotutorial, page 94 and 95 under "feel the magic";
While you're in this window, ....... that it removes the /bin/Debug section.


This is just one of the possible causes of your error message though.
(I also got it when I forgot to put the braces in the right spot.)

greets,
Lis
User avatar
lis
 
Posts: 57
Joined: Thu Nov 30, 2006 1:50 pm
Location: Noord Holland, the Netherlands

Postby lis » Sun Jan 07, 2007 10:34 am

Hi Bren7x64,

Gee I'm sorry I made you think again ;-)

But thanks for the information; I had no idea C# was a product of the B.Gates factory. It does make me a bit more cautious.
I'm still mourning for OS/2 :cry:

greetz,
Lis
:wink:
User avatar
lis
 
Posts: 57
Joined: Thu Nov 30, 2006 1:50 pm
Location: Noord Holland, the Netherlands

Thanks lis ...

Postby zmsc1 » Mon Jan 08, 2007 9:04 pm

... I'm trying to follow the tutorial on a Windows PC - assuming that as this is cross platform, all will be exactly the same. So I don't have the Monodevelop IDE. But I can compile a helloworld and the executable is written to the same directory as the source was in. And the exe runs correctly. And I've done a cut and paste on the code you posted to make sure the braces can't be in the wrong place - but I still get the same error.

I could restart my PC and load up SLED which is the dual boot alternative, then I dare say it would work, but I'm not really trying to prove that Mono works on Linux - I believe that bit - what I really want to show is that Mono works just the same on Windows.

Stuart
zmsc1
 
Posts: 10
Joined: Tue Jan 24, 2006 8:04 pm

Postby lis » Wed Jan 10, 2007 7:48 pm

Hi Stuart,
I'm sorry, but I am really not interested in Windows. :roll:
However:
You seem to be sure it would work in SuSE (gnome), mono and monoDevelop, so I think the best thing for you to solve the problem, is try it yourself by booting into SuSE Linux, and see what's different from your windows version.
GoodLuck.
Lis
User avatar
lis
 
Posts: 57
Joined: Thu Nov 30, 2006 1:50 pm
Location: Noord Holland, the Netherlands

Postby DacidJ » Thu Jan 11, 2007 11:52 pm

Does anybody know? Is there a debugger that integrates with "monoDevelop"?
moneDevelop is a very nice ide, but if there is not a debugger then its not very "i"
And yes I know about mint, but that is CLI and doesn't feel right with the monoDevelop GUI

Why do I want this? because I am trying to teach my son(11) to program and C# looks good for this. But I know that he wont like a CLI debugger :(
Maybe we will stick with C/C++, but it is TOO easy to write dodgy programs in these languages. ( I know - its my dayjob ) dodgy programmer R us ;)
DacidJ
 
Posts: 1
Joined: Thu Jan 11, 2007 11:39 pm

mono debugger

Postby lis » Fri Jan 12, 2007 6:40 pm

I guess you've allready checked this out:
http://www.monodevelop.com/Enabling_the_Debugger

Dated june 2006. So maybe things have changed.

Lis
User avatar
lis
 
Posts: 57
Joined: Thu Nov 30, 2006 1:50 pm
Location: Noord Holland, the Netherlands


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron