Wrox Programmer Forums
|
Intro Programming What is a loop? Which language is best for beginners? What is "object oreinted?" All those types of questions and more are welcome here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Intro Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old March 9th, 2006, 02:28 PM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to MoDulus
Default Enums VS Structs

Anyone mind explaining the differences between enums and structs. they look pretty much the same. So how are they different? Where would you use one over the other?

Thanks
Shaun
Reply With Quote
  #2 (permalink)  
Old March 9th, 2006, 09:01 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Enumerations are a distinct type consisting of a set of named constants called the enumerator list. Every enumeration type has an underlying type, which can be any integral type except char.
Enumerations are integer-types that make code clearer and easier to maintain.

Example:

enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};

A structure is a value type and the instances or objects of a structure are created in stack. A struct can contain fields, methods, constants, constructors, properties, indexers, operators and even other structure types.
Structs are similar to clases, but are intended to be used to group similar items of data together.

Example:

struct MyStruct{
            static int x = 25;
            static int y = 50;

            public void SetXY(int i, int j)
            {
                        x = i;
                        y = j;
            }
            public static void ShowSum()
            {
                        int sum = x + y;
                        Console.WriteLine("The sum is {0}",sum);
            }
}

Understanding Structures in C#: http://www.c-sharpcorner.com/Languag...resInCSRVS.asp
C# Programmer's Reference enum: http://msdn.microsoft.com/library/de...ationtypes.asp

- A.Kahtava
Reply With Quote
  #3 (permalink)  
Old March 10th, 2006, 01:20 AM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to MoDulus
Default

Thank You that makes a lot more sense now. I should know this by now, but oh well. Thanks Again

Shaun
Reply With Quote
  #4 (permalink)  
Old August 2nd, 2011, 10:54 AM
Authorized User
 
Join Date: Feb 2009
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Default Good post

Thanks for your help
http://www.4microsoftsolutions.com
__________________
Rajendar
Reply With Quote
  #5 (permalink)  
Old January 19th, 2012, 10:42 AM
Registered User
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default difference betweenn structures and enumeration

very helpful for me and I find one more link for difference between structure and enumeration

http://www.dotnetquestionanswers.com....msg726#msg726
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
SizeOf Structs CDMBR C# 1 February 21st, 2007 06:24 PM
declaring structs scoobie C++ Programming 3 April 6th, 2006 12:44 AM
Enums.cs allanhu BOOK: ASP.NET Website Programming Problem-Design-Solution 3 November 2nd, 2004 10:37 PM
Enums for accounts??? rcarter BOOK: ASP.NET Website Programming Problem-Design-Solution 3 November 8th, 2003 12:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.