CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2006
    Posts
    38

    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

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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.

  3. #3
    Join Date
    Aug 2000
    Location
    Essex, Uk
    Posts
    1,214

    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

  4. #4
    Join Date
    Mar 2006
    Posts
    38

    Re: Is what i'm coding wright or wrong

    why wrong ,as i know C# support nested Types

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Is what i'm coding wright or wrong

    Quote Originally Posted by Falcon Eyes View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured