Results 1 to 7 of 7

Thread: C# - Cowsay rewrite.

  1. #1
    -grubby is offline May the Ubuntu Be With You!
    Join Date
    Aug 2007
    Beans
    Hidden!

    C# - Cowsay rewrite.

    I'm rewriting cowsay in C# as a practice exercise, and I have this functioning code: http://pastebin.com/m89f6851. However, in my crusade to be a perfectionist, I've written this code: http://pastebin.com/m2cace2df

    This code fails to compile, returning this error:

    Code:
    cowsay.cs(15,9): error CS1002: Expecting `;'
    cowsay.cs(16,9): error CS1002: Expecting `;'
    Compilation failed: 2 error(s), 0 warnings
    I can't quite figure out what's wrong.

    EDIT: Solved.
    Last edited by -grubby; June 18th, 2009 at 12:30 PM.

  2. #2
    Join Date
    Oct 2007
    Beans
    1,914
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: C# - Cowsay rewrite.

    I don't know C#, but I think that it does not make sense to declare a variable that is only visible inside a code block (void Main) to be private. You might need to put the "private string text" outside the main function and replace that line by "text = ....". Same for the next line.

  3. #3
    Join Date
    Aug 2006
    Location
    Madrid, Spain
    Beans
    299
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: C# - Cowsay rewrite.

    You are trying to declare local variables as "private". This makes no sense, but I don't know why the compiler is complaining that it was expecting end-of-statement.
    May the Source be with you.

  4. #4
    -grubby is offline May the Ubuntu Be With You!
    Join Date
    Aug 2007
    Beans
    Hidden!

    Re: C# - Cowsay rewrite.

    Quote Originally Posted by Habbit View Post
    You are trying to declare local variables as "private". This makes no sense, but I don't know why the compiler is complaining that it was expecting end-of-statement.
    I got this crazy idea that would declare them as variables only accessible from the current class. Should I use

    Code:
    string this.text = string.Join(" ", args);
    int this.length = this.text.Length + 2;
    instead?

  5. #5
    Join Date
    Aug 2006
    Location
    Madrid, Spain
    Beans
    299
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: C# - Cowsay rewrite.

    First of all, "Main" is a _static_ method. You don't have access to "this" because there is no current instance. It doesn't matter that you put Main in the Cowsay class: if you want a Cowsay object you have to create it. Second, class variables, either instance or static, must be declared at class scope, not within methods of the class.
    May the Source be with you.

  6. #6
    -grubby is offline May the Ubuntu Be With You!
    Join Date
    Aug 2007
    Beans
    Hidden!

    Re: C# - Cowsay rewrite.

    Quote Originally Posted by Habbit View Post
    First of all, "Main" is a _static_ method. You don't have access to "this" because there is no current instance. It doesn't matter that you put Main in the Cowsay class: if you want a Cowsay object you have to create it. Second, class variables, either instance or static, must be declared at class scope, not within methods of the class.
    Yeah, excuse my mistakes, I feel like I'm trying to write Python code in C#. Anyways, can you post some example code for me? I've looked through a lot of tutorials, and they confused me.

  7. #7
    -grubby is offline May the Ubuntu Be With You!
    Join Date
    Aug 2007
    Beans
    Hidden!

    Re: C# - Cowsay rewrite.

    Well, after some program restructuring, I've come up with a new solution: http://pastebin.com/m3ffe098a.

    Any critique would be nice, too.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •