C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

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




two class in one class

 

two class in one class, get both to work seperately

CCONNER9582002

2 Jun, 2009 - 11:01 AM
Post #1

New D.I.C Head
*

Joined: 21 Apr, 2009
Posts: 30



Thanked: 1 times
My Contributions
I am trying to put create the getscoops class within the icecreamcone class. I need to reference two different classes to the icecreamcone class. I am able to get both codes to work seperately but can't seem to figure out how to put both classes in one class. Could anyone give me a example of how I would accomplish this task.

CODE

using System;
public class icecreamconedemo
{
    public static void Main()
    {
                              getscoops = sp = new getscoops();
        bool isScoopsGood = false;
        while(!isScoopsGood)
        {
            try
            {
                sp.promptgetscoops();
                isScoopsGood = true;
            }
            catch (Exception f)
            {
                Console.WriteLine(f.Message);
            }
        }
    }
}




public class icecreamcone
{


    public class getscoops
    {
        private int numberScoops;
        public void promptgetscoops()
        {
            string strScoops;
            try
            {
                Console.WriteLine("Enter the number of scoops for your cone?");
                strScoops = Console.ReadLine();
                numberScoops = Convert.ToInt32(strScoops);
                if(numberScoops >= 3)
                {
                    icecreamconeException nbe = new
                        icecreamconeException();
                    throw(nbe);
                }
                else
                {
                    Console.WriteLine("Enjoy your icecream.");
                }
            }
            catch(Exception f)
            {
                throw(f);
            }
        }
    }
}





public class icecreamconeException : ApplicationException
{
    private static string msg = "That many scoops will fall off of your cone";
    public icecreamconeException() : base(msg)
    {
    }
}





User is offlineProfile CardPM
+Quote Post


CCONNER9582002

RE: Two Class In One Class

2 Jun, 2009 - 11:24 AM
Post #2

New D.I.C Head
*

Joined: 21 Apr, 2009
Posts: 30



Thanked: 1 times
My Contributions
QUOTE(CCONNER9582002 @ 2 Jun, 2009 - 11:01 AM) *

I am trying to put create the getscoops class within the icecreamcone class. I need to reference two different classes to the icecreamcone class. I am able to get both codes to work seperately but can't seem to figure out how to put both classes in one class. Could anyone give me a example of how I would accomplish this task.

CODE

using System;
public class icecreamconedemo
{
    public static void Main()
    {
                              getscoops = sp = new getscoops();
        bool isScoopsGood = false;
        while(!isScoopsGood)
        {
            try
            {
                sp.promptgetscoops();
                isScoopsGood = true;
            }
            catch (Exception f)
            {
                Console.WriteLine(f.Message);
            }
        }
    }
}




public class icecreamcone
{


    public class getscoops
    {
        private int numberScoops;
        public void promptgetscoops()
        {
            string strScoops;
            try
            {
                Console.WriteLine("Enter the number of scoops for your cone?");
                strScoops = Console.ReadLine();
                numberScoops = Convert.ToInt32(strScoops);
                if(numberScoops >= 3)
                {
                    icecreamconeException nbe = new
                        icecreamconeException();
                    throw(nbe);
                }
                else
                {
                    Console.WriteLine("Enjoy your icecream.");
                }
            }
            catch(Exception f)
            {
                throw(f);
            }
        }
    }
}





public class icecreamconeException : ApplicationException
{
    private static string msg = "That many scoops will fall off of your cone";
    public icecreamconeException() : base(msg)
    {
    }
}



I am using c# to program

User is offlineProfile CardPM
+Quote Post

CCONNER9582002

RE: Two Class In One Class

2 Jun, 2009 - 11:56 AM
Post #3

New D.I.C Head
*

Joined: 21 Apr, 2009
Posts: 30



Thanked: 1 times
My Contributions
I guess I will just have to figure this one out on my own like I did the other two parts.
User is offlineProfile CardPM
+Quote Post

masteryee

RE: Two Class In One Class

2 Jun, 2009 - 12:29 PM
Post #4

D.I.C Regular
***

Joined: 16 May, 2009
Posts: 266



Thanked: 36 times
My Contributions
icecreamcone.getscoops sp = new icecreamcone.getscoops();

This post has been edited by masteryee: 2 Jun, 2009 - 12:29 PM
User is offlineProfile CardPM
+Quote Post

BetaWar

RE: Two Class In One Class

2 Jun, 2009 - 01:03 PM
Post #5

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 4,729



Thanked: 269 times
Dream Kudos: 1400
My Contributions
Moved to C#
User is offlineProfile CardPM
+Quote Post

SwiftStriker00

RE: Two Class In One Class

11 Jun, 2009 - 10:14 AM
Post #6

D.I.C Regular
Group Icon

Joined: 25 Dec, 2008
Posts: 295



Thanked: 18 times
Dream Kudos: 125
My Contributions
Are you looking for 2 classes, one after the other. Or you looking for inner classes (one nested in the other)?

you can just use a namespace to keep them together
CODE

namespace Icecream{
     public class A{...}
     public class B{...}
         public class E:Exception{...}
}


This post has been edited by SwiftStriker00: 11 Jun, 2009 - 10:15 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 09:56PM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month