The following code works for me in a console application:
Code:
using System;
using System.Collections.Generic;
using System.Net.Sockets;
namespace Structs
{
class Program
{
static void Main(string[] args)
{
TestStruct1 ts1; //No 'new TestStruct1()' needed.
ts1.Sockets = new List<Socket>();
Socket socket1 = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IPv4);
ts1.Sockets.Add(socket1);
Socket socket2 = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IPv6);
ts1.Sockets.Add(socket2);
foreach (Socket socket in ts1.Sockets)
{
Console.WriteLine("Address Family: {0}, Socket Type: {1}, Protocol Type: {2}.", socket.AddressFamily, socket.SocketType, socket.ProtocolType);
}
Console.ReadLine();
}
}
struct TestStruct1
{
public List<Socket> Sockets;
}
}
Something you can't do is initialise struct members within the struct itself and notice you don't need to use new when declaring the struct as it's a value type, like Integer32 (int).
--
Joe (
Microsoft MVP - XML)