|
-
June 13th, 2010, 06:57 AM
#1
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
-
June 14th, 2010, 02:37 AM
#2
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.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
-
June 14th, 2010, 03:00 AM
#3
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.
If you find my answers helpful, dont forget to rate me 
-
June 15th, 2010, 03:03 AM
#4
Re: Is what i'm coding wright or wrong
why wrong ,as i know C# support nested Types
-
June 15th, 2010, 03:27 AM
#5
Re: Is what i'm coding wright or wrong
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|