c#用StreamReader对文件读取

该段代码展示了如何在C#中使用StreamReader读取当前目录下名为'MacroType'的文件夹中,与指定类型名匹配的.bat文件内容。通过遍历文件、打开并读取内容,然后进行字符串处理,根据读取的数据动态创建直线阵列或交叉阵列的阵子间距界面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/// <summary>
        ///类型:阵列反显,处理代码
        /// </summary>
        public void OnTypeArrayShowItem()
        {
            //找到和 当前选择的类型名 对应的 天线类型文件
            string folderPath = System.Environment.CurrentDirectory;
            DirectoryInfo TheFolder = new DirectoryInfo(folderPath + "\\MacroType");
            //遍历文件
            FileInfo currentTypeArrayFile = null;
            foreach (FileInfo nextInfo in TheFolder.GetFiles())
            {
                if (nextInfo.Name.Replace(".bat", "").Equals(this.Entity.AntennaType))
                {
                    currentTypeArrayFile = nextInfo;
                    break;
                }
            }
            //读取对应的天线类型文件
            // OpenText 创建一个UTF-8 编码的StreamReader对象
            StreamReader currentTypeArraySR = currentTypeArrayFile.OpenText();
            // 全部读完
            string currentTypeArrayStr = currentTypeArraySR.ReadToEnd();
            //Split方法:要省略返回的数组中的空数组元素,则为 System.StringSplitOptions.RemoveEmptyEntries;
            string[] currentTypeArrayArr = currentTypeArrayStr.Split(new string[] { ";\r\n" }, System.StringSplitOptions.RemoveEmptyEntries);
            //阵子/横向阵子数
            string BitNum = currentTypeArrayArr[2];
            //动态加载出阵列
            ArrayVisibility = "Visible";
            if ("直线阵列".Equals(currentTypeArrayArr[1]))
            {
                //创建直线阵列阵子间距界面
                var trendsViewModel = new TrendsViewModel(this.Messenger, this.UserLogin);
                if (BitNum != null && BitNum != "")
                {
                    trendsViewModel.CreatLostFocus(int.Parse(BitNum), "1");
                    trendsViewModel.WriteBitNum(currentTypeArrayArr[3]);
                    BitViewModel = trendsViewModel;
                }
            }
            else if ("交叉阵列".Equals(currentTypeArrayArr[1]))
            {
                //纵向阵子数
                string PortraitBitNum = currentTypeArrayArr[3];
                //交叉点左通道数
                string CrossLeftBitNum = currentTypeArrayArr[4].Split(',')[0];
                //交叉点上通道数
                string CrossTopBitNum = currentTypeArrayArr[4].Split(',')[1];



                //创建交叉阵列阵子间距界面
                var transverseTrendsViewModel = new TrendsViewModel(this.Messenger, this.UserLogin);
                transverseTrendsViewModel.CreatLostFocus(int.Parse(BitNum), int.Parse(PortraitBitNum), CrossLeftBitNum, CrossTopBitNum);
                transverseTrendsViewModel.WriteBitNum(currentTypeArrayArr[5]);
                BitViewModel = transverseTrendsViewModel;
            }


            

        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值