Results 1 to 5 of 5

Thread: Iteration Problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Iteration Problem

    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Resources;
    
    namespace Proxy
    {
        class Program
        {
            static void Main(string[] args)
            {
                ProxyInfo[] Proxy = new ProxyInfo();
                foreach (string p in Resource.Proxies)
                {
                 
                }
                
            }
        }
    
        public struct ProxyInfo
        {
            private string Username;
            private string Password;
            private string Address;
            private short  Port;
            private int    Type;
    
            public string  Username
            {
                get
                {
                    return Username;
                }
                set
                {
                    Username = value;
                }
            }
            public string  Password
            {
                get
                {
                    return Password;
                }
                set
                {
                    Password = value;
                }
            }
            public string  Address
            {
                get
                {
                    return Address;
                }
                set
                {
                    Address = value;
                }
            }
            public short   Port
            {
                get
                {
                    return Port;
                }
                set
                {
                    Port = value;
                }
            }
            public int     Type
            {
                get
                {
                    return Type;
                }
                set
                {
                    Type = value;
                }
            }
        }
    }
    my Proxies Resource has this in it

    Code:
    201.12.189.79:1080@SOCKS4
    71.206.139.211:5219@SOCKS4
    24.147.237.50:10961@SOCKS4
    59.148.66.123:32167@SOCKS4
    59.30.182.9:4769@SOCKS4
    69.242.39.99:5740@SOCKS5
    201.12.150.87:1080@SOCKS5
    24.147.237.50:10961@SOCKS5
    201.53.226.112:1080@SOCKS5
    68.188.194.36:5882@SOCKS5
    I am trying to get it so it's like Proxy[p].Username, password, etc... I can't seem to figure out how to split up the line effectively and assign it to the array. I also wanted to make an Enumerator for SOCKSv4, SOCKSv4a, SOCKSv5 for the Type Property but i couldn't get that to work out either.

    Thanks for the help

    - Joel
    There are only two kinds of people who are truely fascinating: people who know absolutely everything, and people who know absolutely nothing.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Iteration Problem

    It's an "enumeration", not an "enumerator". An enumerator is something else entirely.
    Code:
    public enum SocksType
    {
        SOCKS4,
        SOCKS4a,
        SOCKS5
    }
    Your structure isn't going to work because you've given the private fields and public properties the same name. You'd normally start the field names with a lower case letter and the property names with an upper case letter. I also like to add an underscore to the front of the field name to make the difference more obvious.
    Code:
    public struct ProxyInfo
    {
        private string _userName;
        private string _password;
        private string _address;
        private short _port;
        private SocksType _type;
    
        public string UserName
        {
            get { return _userName; }
            set { _userName = value; }
        }
    
        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }
    
        public string Address
        {
            get { return _address; }
            set { _address = value; }
        }
    
        public short Port
        {
            get { return _port; }
            set { _port = value; }
        }
    
        public SocksType Type
        {
            get { return _type; }
            set { _type = value; }
        }
    
        public ProxyInfo(string proxyString)
        {
            this._userName = string.Empty;
            this._password = string.Empty;
    
            // You should probably use a Regex to validate the string but I'll leave that to you.
    
            string[] proxyParts = proxyString.Split(':', '@');
    
            this._address = proxyParts[0];
            this._port = short.Parse(proxyParts[1]);
            this._type = (SocksType)(Enum.Parse(typeof(SocksType), proxyParts[2]));
        }
    }
    Note the addition of the constructor that will parse your string and set the properties of the ProxyInfo object accordingly. You now have to change your Main method, which is syntactically incorrect. The first line is trying to create a single ProxyInfo object and assign it to a ProxyInfo array variable, which isn't going to work:
    Code:
    public void Main()
    {
        ProxyInfo[] proxies = new ProxyInfo[Resource.Proxies.Length];
    
        for (int i = 0; i < proxies.Length; i++)
        {
            proxies[i] = new ProxyInfo(Resource.Proxies[i]);
        }
    }
    I'm not 100% sure what Resource.Proxies is, so you may have to adjust that slightly.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Iteration Problem

    Note that you can use the in-built "prop" code snippet to help you define a property. Just type "prop" and then hit the Tab key twice to generate a generic property definition. You can the set the type and name of private field to update the property defintion to the correct type and to use the correct field name. Use the Tab key to move amongst the highlighted parts of the snippet.
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2003
    Location
    Eden Prairie Minnesota
    Posts
    301

    Re: Iteration Problem

    Yeah, i was planning on using a regex match for validation but i haven't got that far.

    You always have the best posts with most usefull stuff in them, Thank you very very much ~

    Also, what would be the best way to format the proxy address. like username[email protected]:1080 should i put like @ SOCKS4/5 at the end... or what do you think?
    Last edited by BaDDBLooD; Aug 5th, 2006 at 08:44 PM.
    There are only two kinds of people who are truely fascinating: people who know absolutely everything, and people who know absolutely nothing.

  5. #5
    Fanatic Member
    Join Date
    Jan 2005
    Location
    Cebu
    Posts
    607

    Re: Iteration Problem

    Quote Originally Posted by jmcilhinney
    Note that you can use the in-built "prop" code snippet to help you define a property. Just type "prop" and then hit the Tab key twice to generate a generic property definition. You can the set the type and name of private field to update the property defintion to the correct type and to use the correct field name. Use the Tab key to move amongst the highlighted parts of the snippet.
    This maybe an out of topic post but I just want to give a smile of the prop Tab key feature in VS.NET. Code refactoring in Netbeans still is a good thing, better than VS.


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