Click here to Skip to main content
15,888,579 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using strings from external .txt file Pin
Tetra10445-Feb-15 3:06
Tetra10445-Feb-15 3:06 
QuestionHow to share a server connection between different powershell runspaces in c# on a web application Pin
tasoss2-Feb-15 21:37
tasoss2-Feb-15 21:37 
QuestionRe: How to share a server connection between different powershell runspaces in c# on a web application Pin
Richard MacCutchan3-Feb-15 0:38
mveRichard MacCutchan3-Feb-15 0:38 
AnswerRe: How to share a server connection between different powershell runspaces in c# on a web application Pin
tasoss3-Feb-15 0:59
tasoss3-Feb-15 0:59 
SuggestionReceiving Windows Message in class library asynchronously in C# Pin
Ram Kumar2-Feb-15 18:07
Ram Kumar2-Feb-15 18:07 
GeneralRe: Receiving Windows Message in class library asynchronously in C# Pin
Richard Deeming4-Feb-15 1:53
mveRichard Deeming4-Feb-15 1:53 
QuestionStruct and Enum Pin
Member 111616252-Feb-15 18:05
Member 111616252-Feb-15 18:05 
AnswerRe: Struct and Enum Pin
OriginalGriff2-Feb-15 21:13
mveOriginalGriff2-Feb-15 21:13 
They are totally different things.
An enum is a list of named constants which are (generally, but not always they can be byte, sbyte, short, ushort, uint, long, or ulong instead) integer.
They are used to "group" related values such as the results you can get when you toss a coin: Heads and Tails
C#
public enum CoinResult
    {
    Heads,
    Tails,
    }
The system handles the values assigned to CoinResult.Heads and CoinResult.Tails - and you just use the names in your code:
C#
CoinResult toss = FlipTheCoin(coin);
switch(toss)
   {
   default: throw new ArgumentException("Unknown CoinResult: " + toss);
   case CoinResult.Heads: 
      Console.WriteLine("It came down heads up.");
      break;
   case CoinResult.Tails: 
      Console.WriteLine("It came down with the tails showing.");
      break;
   }

This makes your code a lot more readable:
C#
int toss = FlipTheCoin(coin);
switch(toss)
   {
   default: throw new ArgumentException("Unknown coin flip state: " + toss);
   case 1: 
      Console.WriteLine("It came down heads up.");
      break;
   case 2: 
      Console.WriteLine("It came down with the tails showing.");
      break;
   }

And enum doesn't have fields, properties, events, or methods; and cannot be used to derive a new type. See here: https://msdn.microsoft.com/en-us/library/sbbt4032.aspx[^]

A struct is different: it's a "slimline class". For the moment when you see struct you can mentally replace it with class - there are significant differences, but your tutor or book will cover these later. For reference, there is this: Using struct and class - what's that all about?[^] but I would recommend that you don't read it yet - it's a bit advanced and is likely to confuse you until you are a little further into your course. Read it later! Laugh | :laugh:
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

AnswerRe: Struct and Enum Pin
BillWoodruff3-Feb-15 21:01
professionalBillWoodruff3-Feb-15 21:01 
AnswerRe: Struct and Enum Pin
V.3-Feb-15 22:02
professionalV.3-Feb-15 22:02 
Questionhow do I change a regex Pin
Member 113543862-Feb-15 11:55
Member 113543862-Feb-15 11:55 
AnswerRe: how do I change a regex Pin
Tomáš Podešva2-Feb-15 17:14
professionalTomáš Podešva2-Feb-15 17:14 
AnswerRe: how do I change a regex Pin
OriginalGriff2-Feb-15 21:18
mveOriginalGriff2-Feb-15 21:18 
GeneralRe: how do I change a regex Pin
Member 113543863-Feb-15 14:03
Member 113543863-Feb-15 14:03 
GeneralRe: how do I change a regex Pin
OriginalGriff3-Feb-15 23:28
mveOriginalGriff3-Feb-15 23:28 
Questionwindows 8 hybrid shutdown notification Pin
morglorf2-Feb-15 11:33
morglorf2-Feb-15 11:33 
AnswerRe: windows 8 hybrid shutdown notification Pin
Richard Andrew x642-Feb-15 11:53
professionalRichard Andrew x642-Feb-15 11:53 
GeneralRe: windows 8 hybrid shutdown notification Pin
morglorf2-Feb-15 12:17
morglorf2-Feb-15 12:17 
GeneralRe: windows 8 hybrid shutdown notification Pin
morglorf3-Feb-15 5:54
morglorf3-Feb-15 5:54 
QuestionHelp with Array search. Pin
Member 114193361-Feb-15 18:18
Member 114193361-Feb-15 18:18 
AnswerRe: Help with Array search. Pin
Richard Andrew x641-Feb-15 18:34
professionalRichard Andrew x641-Feb-15 18:34 
GeneralRe: Help with Array search. Pin
Member 114193361-Feb-15 19:28
Member 114193361-Feb-15 19:28 
AnswerRe: Help with Array search. Pin
BillWoodruff1-Feb-15 21:16
professionalBillWoodruff1-Feb-15 21:16 
AnswerRe: Help with Array search. Pin
Richard Deeming2-Feb-15 2:53
mveRichard Deeming2-Feb-15 2:53 
AnswerRe: Help with Array search. Pin
ramazan aktolu3-Feb-15 7:36
ramazan aktolu3-Feb-15 7:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.