Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,094 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,594 people online right now. Registration is fast and FREE... Join Now!




C# creating classes

 
Reply to this topicStart new topic

C# creating classes

iamanidiot
10 Nov, 2007 - 02:58 PM
Post #1

New D.I.C Head
*

Joined: 10 Nov, 2007
Posts: 1


My Contributions
CODE

public class Chair
{

  public int height;
  public int width;
  public string color;

  public void Fold(int easy);
}


I am trying to create a method that accepts one type of bool.

If the parameter is true, the method displays the word folding, if it is false is, the method displays the word unfolding.

I don't understand how to use my bool. Please help

*Always use code blocks please smile.gif ==> code.gif

This post has been edited by PsychoCoder: 11 Nov, 2007 - 06:51 AM
User is offlineProfile CardPM
+Quote Post

baavgai
RE: C# Creating Classes
10 Nov, 2007 - 03:51 PM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,019



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
Display how? Here's an example of what you might be looking for:
CODE

public class Chair {
   public int height;
   public int width;
   public string color;
   private bool isFolding;
   public  Chair() {
      this.SetFolding(true);
   }
   public void SetFolding(bool isFolding) {
      this.isFolding=isFolding;
   }
   public string GetChairName() {
      if (this.isFolding) {
          return "Folding";
      } else {
          return "Unfolding";
      }
   }
}


Hope this helps.
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: C# Creating Classes
11 Nov, 2007 - 06:50 AM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,983



Thanked: 125 times
Dream Kudos: 8600
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
baavgai gave you a creat example of doing this, if that is indeed what you are looking for, in my opinion though there is one change I would make to his code, that would be I would change

CODE

public string GetChairName() {
      if (this.isFolding) {
          return "Folding";
      } else {
          return "Unfolding";
      }
   }


To a ReadOnly property of the Class Object, like this

CODE

public string GetChairName
{
     get
         {
               If(this.Folding)
               {
                    return "Folding";
                }
                 else
                  {
                      return "Unfolding";
                   }
          }
}


But once again this is personal preference, both solutions will work nicely for you're looking for smile.gif
User is online!Profile CardPM
+Quote Post

baavgai
RE: C# Creating Classes
11 Nov, 2007 - 07:08 AM
Post #4

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,019



Thanked: 105 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions
Actually, I would have preferred a property as well. However, "the method displays" description seemed to dictate the design. tongue.gif

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 08:25PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month