i'm learning for myself c# in visual studio, so I have a error.
Field "MainWindow.port" is never assigned a value, so it will always have default value null.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO.Ports;
namespace WpfApp15
{
public partial class MainWindow : Window
{
SerialPort port;
public MainWindow()
{
InitializeComponent();
SerialPort port = new SerialPort();
port.BaudRate = 9600;
port.PortName = "COM4";
port.Open();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
port.WriteLine("1");
}
}
}