Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
Questionmoving from iphone to asp.net Pin
dsp120-Mar-14 23:41
dsp120-Mar-14 23:41 
AnswerRe: moving from iphone to asp.net Pin
Vishal Pand3y21-Mar-14 0:06
Vishal Pand3y21-Mar-14 0:06 
AnswerRe: moving from iphone to asp.net Pin
OriginalGriff21-Mar-14 2:16
mveOriginalGriff21-Mar-14 2:16 
QuestionMany instances of the same class by a loop Pin
mrRsChief20-Mar-14 15:32
mrRsChief20-Mar-14 15:32 
AnswerRe: Many instances of the same class by a loop Pin
Dave Kreskowiak20-Mar-14 17:06
mveDave Kreskowiak20-Mar-14 17:06 
AnswerRe: Many instances of the same class by a loop Pin
Wayne Gaylard20-Mar-14 20:03
professionalWayne Gaylard20-Mar-14 20:03 
AnswerRe: Many instances of the same class by a loop Pin
V.20-Mar-14 20:42
professionalV.20-Mar-14 20:42 
AnswerRe: Many instances of the same class by a loop Pin
OriginalGriff20-Mar-14 23:27
mveOriginalGriff20-Mar-14 23:27 
Just to add to the previous answers: you can't do that anyway.
C#
foreach (string name in arrayNames)
    {
    horse name = new horse();
    }

Because the declaration of your new horse inside the loop "hides" the name of the string used in the foreach - which will give you a compilation error:
A local variable named 'name' cannot be declared in this scope because it would give a different meaning to 'name', which is already used in a 'parent or current' scope to denote something else

Instead, you probably want to call it "horse" or similar so that you can access both the horse instance you just created and the name you want to give it.

BTW: You should try to follow naming conventions as they make everything slightly more understandable. And one of the conventions is that class names start with an uppercase letter: "Horse" rather than "horse":
C#
    string[] arrayNames = new string[] { "Trigger", "Royal", "Crown" };
    List<Horse> horses = new List<Horse>();
    foreach (string name in arrayNames)
        {
        Horse horse = new Horse();
        horse.Name = name;
        horses.Add(horse);
        }
...
public class Horse
    {
    public string Name { get; set; }
    public int Age { get; set; }
    public Color Colour { get; set; }
    public string Sex { get; set; }
    }

Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

AnswerRe: Many instances of the same class by a loop Pin
BobJanova21-Mar-14 0:28
BobJanova21-Mar-14 0:28 
QuestionAny Protobuf guru's here? Have problem with outputted data. Pin
DeepToot20-Mar-14 10:23
DeepToot20-Mar-14 10:23 
AnswerRe: Any Protobuf guru's here? Have problem with outputted data. Pin
Pete O'Hanlon20-Mar-14 13:46
mvePete O'Hanlon20-Mar-14 13:46 
GeneralRe: Any Protobuf guru's here? Have problem with outputted data. Pin
DeepToot21-Mar-14 3:29
DeepToot21-Mar-14 3:29 
QuestionWCF SSL overhead? Pin
SledgeHammer0120-Mar-14 9:35
SledgeHammer0120-Mar-14 9:35 
SuggestionRe: WCF SSL overhead? Pin
Richard MacCutchan20-Mar-14 22:41
mveRichard MacCutchan20-Mar-14 22:41 
QuestionC# Increase Hours and Minutes (TimeSpan) Pin
nicola_melc20-Mar-14 7:48
nicola_melc20-Mar-14 7:48 
AnswerRe: C# Increase Hours and Minutes (TimeSpan) Pin
Pete O'Hanlon20-Mar-14 8:01
mvePete O'Hanlon20-Mar-14 8:01 
GeneralRe: C# Increase Hours and Minutes (TimeSpan) Pin
nicola_melc20-Mar-14 8:14
nicola_melc20-Mar-14 8:14 
GeneralRe: C# Increase Hours and Minutes (TimeSpan) Pin
Pete O'Hanlon20-Mar-14 8:14
mvePete O'Hanlon20-Mar-14 8:14 
QuestionWPF problem with ScrollViewer Pin
Federico Barbieri20-Mar-14 6:50
Federico Barbieri20-Mar-14 6:50 
QuestionRe: WPF problem with ScrollViewer Pin
Kenneth Haugland20-Mar-14 20:43
mvaKenneth Haugland20-Mar-14 20:43 
SuggestionRe: WPF problem with ScrollViewer Pin
Richard MacCutchan20-Mar-14 22:40
mveRichard MacCutchan20-Mar-14 22:40 
GeneralRe: WPF problem with ScrollViewer Pin
Federico Barbieri20-Mar-14 23:47
Federico Barbieri20-Mar-14 23:47 
Question//solved// help making class available to all Pin
Bosskardo20-Mar-14 4:19
Bosskardo20-Mar-14 4:19 
AnswerRe: help making class available to all Pin
Pete O'Hanlon20-Mar-14 4:57
mvePete O'Hanlon20-Mar-14 4:57 
AnswerRe: help making class available to all Pin
OriginalGriff20-Mar-14 5:56
mveOriginalGriff20-Mar-14 5:56 

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.