Is what i'm coding wright or wrong
Hi Every Body
pls some one tell me if what i'm coding below is write or wrong , i wrote main class called "Family" inside the Family class i defined a structure called "Son" as follow
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test2del
{
public class Family
{
string motherName;
string fatherName;
public string famName;
Son[] FamilyColl = new Son[5];
public Family(string fn, string mn)
{
motherName = mn;
fatherName = fn;
}
public struct Son
{
string SonName;
String kind;
float age;
public Son(string sn, string sk, float sa)
{
SonName = sn;
kind = sk;
age = sa;
}
public string GetSonName
{
get { return SonName; }
}
}
}
}
in the main Program file, i defied object of type Family and no problem
also i want to define an object of type Sun and this is the problem how can i do it
Re: Is what i'm coding wright or wrong
It is wrong. At least, there is no reason for Son to be struct and nested in Family class. For difference between class and struct, you can look here.
Re: Is what i'm coding wright or wrong
Also check out interfaces. The common thing between all of them is Name, So this is a prime candidate for an interface especially if it's required.
Re: Is what i'm coding wright or wrong
why wrong ,as i know C# support nested Types
Re: Is what i'm coding wright or wrong
Quote:
Originally Posted by
Falcon Eyes
why wrong ,as i know C# support nested Types
Ask yourself what you gain by nesting the struct inside the class. If it doesn't gain you anything, then you probably shouldn't do it.