0

I want to convert the string the server is receiving from the client to in an array. However when I use the String.Split method the result variable is showing null. Anyone know why that might be?

Array is not filled when using <code>split</code>

namespace ExampleLib.Server
{

    public class Server
    {
        private class ConnectedClient
        {
            public int ID { get; }
            private TcpClient _client;
            private StreamReader _streamReader;

            public delegate void NetDataEventHandler(object sender, NetDataEventArgs e);

            public event NetDataEventHandler NetData;

            public virtual void OnNetData(NetDataEventArgs e)
            {
                NetData?.Invoke(this, e);
            }

            public class NetDataEventArgs
            {
                public NetDataEventArgs(int id, string message)
                {
                    ID = id;
                    Message = message;
                }

                public string Message { get; }
                public int ID { get; }
            }
        public ConnectedClient(int id, TcpClient client)
          {
            ID = id;
            _client = client;
           }

    private void ClientReceiveData(object sender, ConnectedClient.NetDataEventArgs e)
            {
                if (string.IsNullOrEmpty(e.Message) == false)
                {
                    Trace.WriteLine($" Client {e.ID}: {e.Message}");
                    var result = e.Message.Split(',');
                }
            }
3
  • 2
    result shows null because that line hasn't executed yet. You haven't finished the assignment to the variable. What happens if you press F10? Commented Aug 15, 2018 at 17:50
  • 1
    Have you stepped forward in your debugger to check if the variable was assigned? Your image is at the step, but result won't be assigned until you continue past that step. Commented Aug 15, 2018 at 17:51
  • Ya it works my apologies I didn't realize I had the break-point at the variable. Commented Aug 15, 2018 at 17:56

1 Answer 1

2

You have stopped at the break-point.

You should proceed one more step, in order for that line to be executed.

Currently, you're at a step similar to this.

enter image description here

If you proceed one more step using F10 (or 'Step Over' button) , it will execute that line and assign the value of addition to c in this example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.