C# File.ReadAllLines的代码示例

通过代码示例来学习C# File.ReadAllLines方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


File.ReadAllLines是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的File.ReadAllLines() 已经帮大家高亮显示了,大家可以重点学习File.ReadAllLines() 方法的写法,从而快速掌握该方法的应用。

File.ReadAllLines的代码示例1 - GetFilesFromFile()

    using System.IO;

        private static IEnumerable GetFilesFromFile(string fileName, out string error)
        {
            error = null;
            if (string.IsNullOrWhiteSpace(fileName))
            {
                return Enumerable.Empty();
            }

            if (!File.Exists(fileName))
            {
                error = string.Format("Could not find '{0}' list file.", fileName);
                return Enumerable.Empty();
            }

            return File.ReadAllLines(fileName)
                        .Select(line => line.Trim());
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:19,代码来源:BlobPrefetcher.cs

在GetFilesFromFile()方法中,File的代码示例类中的ReadAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.ReadAllLines的代码示例2 - Execute()

    using System.IO;

        public override void Execute()
        {
            this.ValidatePathParameter(this.EnlistmentRootPathParameter);

            this.Output.WriteLine("Most recent log files:");

            string errorMessage;
            string enlistmentRoot;
            if (!GVFSPlatform.Instance.TryGetGVFSEnlistmentRoot(this.EnlistmentRootPathParameter, out enlistmentRoot, out errorMessage))
            {
                this.ReportErrorAndExit(
                    "Error: '{0}' is not a valid GVFS enlistment",
                    this.EnlistmentRootPathParameter);
            }

            string gvfsLogsRoot = Path.Combine(
                enlistmentRoot,
                GVFSPlatform.Instance.Constants.DotGVFSRoot,
                GVFSConstants.DotGVFS.LogName);

            if (this.LogType == null)
            {
                this.DisplayMostRecent(gvfsLogsRoot, GVFSConstants.LogFileTypes.Clone);

                // By using MountPrefix ("mount") DisplayMostRecent will display either mount_verb, mount_upgrade, or mount_process, whichever is more recent
                this.DisplayMostRecent(gvfsLogsRoot, GVFSConstants.LogFileTypes.MountPrefix);
                this.DisplayMostRecent(gvfsLogsRoot, GVFSConstants.LogFileTypes.Prefetch);
                this.DisplayMostRecent(gvfsLogsRoot, GVFSConstants.LogFileTypes.Dehydrate);
                this.DisplayMostRecent(gvfsLogsRoot, GVFSConstants.LogFileTypes.Repair);
                this.DisplayMostRecent(gvfsLogsRoot, GVFSConstants.LogFileTypes.Sparse);

                string serviceLogsRoot = GVFSPlatform.Instance.GetLogsDirectoryForGVFSComponent(GVFSConstants.Service.ServiceName);
                this.DisplayMostRecent(serviceLogsRoot, GVFSConstants.LogFileTypes.Service);
            }
            else
            {
                string logFile = FindNewestFileInFolder(gvfsLogsRoot, this.LogType);
                if (logFile == null)
                {
                    this.ReportErrorAndExit("No log file found");
                }
                else
                {
                    foreach (string line in File.ReadAllLines(logFile))
                    {
                        this.Output.WriteLine(line);
                    }
                }
            }
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:52,代码来源:LogVerb.cs

在Execute()方法中,File的代码示例类中的ReadAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.ReadAllLines的代码示例3 - MergeHooks()

    using System.IO;

        private static string MergeHooks(GVFSContext context, string configSettingName, string hookName)
        {
            GitProcess configProcess = new GitProcess(context.Enlistment);
            string filename;
            string[] defaultHooksLines = { };

            // Pass false for forceOutsideEnlistment to allow hooks to be configured at the per-repo level
            if (configProcess.TryGetFromConfig(configSettingName, forceOutsideEnlistment: false, value: out filename) && filename != null)
            {
                filename = filename.Trim(' ', '\n');
                defaultHooksLines = File.ReadAllLines(filename);
            }

            return HooksInstaller.MergeHooksData(defaultHooksLines, filename, hookName);
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:17,代码来源:WindowsGitHooksInstaller.cs

在MergeHooks()方法中,File的代码示例类中的ReadAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.ReadAllLines的代码示例4 - Fix_Issue_60()

    
        [Fact]
        [Description("Issue #60")]
        public void Fix_Issue_60()
        {
            var project = new Project("MyProduct",
                              new Dir("%ProgramFiles%",
                              new File("abc.txt", new FilePermission("Guest", GenericPermission.All))));

            project.AddAction(new WixQuietExecAction("cmd.exe", "/c \"echo abc\""));

            var batchFile = project.BuildMsiCmd();
            string cmd = System.IO.File.ReadAllLines(batchFile).First();

            int firstPos = cmd.IndexOf("WixUtilExtension.dll");
            int lastPos = cmd.LastIndexOf("WixUtilExtension.dll");

            Assert.Equal(firstPos, lastPos);
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:19,代码来源:IssueFixesTest.cs

在Fix_Issue_60()方法中,File的代码示例类中的ReadAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.ReadAllLines的代码示例5 - CalculateHashes()

    using System.IO;

        private static void CalculateHashes()
        {
            string dir = Path.Combine(Runtime.ExecutableDir, "Hashes");
            if (!Directory.Exists(dir))
                return;

            foreach (var file in Directory.GetFiles(dir))
            {
                if (Utils.GetExtension(file) != ".txt")
                    continue;

                foreach (string hashStr in File.ReadAllLines(file))
                {
                    CheckHash(hashStr);
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:19,代码来源:BCSVParse.cs

在CalculateHashes()方法中,File的代码示例类中的ReadAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.ReadAllLines的代码示例6 - CreateHashList()

    using System.IO;

        private static void CreateHashList()
        {
            string dir = Path.Combine(Runtime.ExecutableDir, "Hashes");
            if (!Directory.Exists(dir))
                return;

            foreach (var file in Directory.GetFiles(dir))
            {
                if (Utils.GetExtension(file) != ".txt")
                    continue;

                foreach (string hashStr in File.ReadAllLines(file)) {
                    CheckHash(hashStr);
                }
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:18,代码来源:BYAML.cs

在CreateHashList()方法中,File的代码示例类中的ReadAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.ReadAllLines的代码示例7 - InitializeHashCache()

    using System.IO;

        public static void InitializeHashCache()
        {
            HashBinaryPath = Path.Combine(Runtime.ExecutableDir, "Hashes", "GFPAKHashCache.bin");
            string HashExtraPath = Path.Combine(Runtime.ExecutableDir, "Hashes", "GFPAK.txt");

            bool NeedsBaseCacheRebuild = true;
            CurrentVersionHash = GetToolboxVersionHash();

            if (File.Exists(HashBinaryPath))
            {
                using (BinaryReader Reader = new BinaryReader(new FileStream(HashBinaryPath, FileMode.Open)))
                {
                    ulong CacheVersionHash = Reader.ReadUInt64();
                    NeedsBaseCacheRebuild = CacheVersionHash != CurrentVersionHash;
                    uint Count = Reader.ReadUInt32();
                    for (uint HashIndex = 0; HashIndex < Count; HashIndex++)
                    {
                        ulong HashCode = Reader.ReadUInt64();
                        string HashName = Reader.ReadString();
                        PutHash(HashCode, HashName);
                    }
                }
            }

            if (NeedsBaseCacheRebuild)
            {
                GenerateBaseHashList();
            }

            if (File.Exists(HashExtraPath))
            {
                string[] UserHashLines = File.ReadAllLines(HashExtraPath);
                foreach (string Line in UserHashLines){
                    PutHash(Line);
                }
            }

            WriteCache();
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:41,代码来源:GFPAKHashCache.cs

在InitializeHashCache()方法中,File的代码示例类中的ReadAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

File.ReadAllLines的代码示例8 - RotateFile()

    using System.IO;

        private static void RotateFile(ProgressLog log,  string filename, string outfile, string[] args)
        {
            double dx = 0;
            double dy = 0;
            double cx = 0;
            double cy = 0;
            double angle = 0;
            if (args.Count() > 2) double.TryParse(args[2], out dx);
            if (args.Count() > 3) double.TryParse(args[3], out dy);
            if (args.Count() > 4) double.TryParse(args[4], out cx);
            if (args.Count() > 5) double.TryParse(args[5], out cy);
            if (args.Count() > 6) double.TryParse(args[6], out angle);

            var T = Gerber.FindFileType(filename);
            if (T == BoardFileType.Drill)
            {
                ExcellonFile EF = new ExcellonFile();
                EF.Load(log, filename);
                EF.Write(outfile, dx, dy, cx, cy, angle);
            }
            else
            {
                BoardSide Side;
                BoardLayer Layer;
                Gerber.DetermineBoardSideAndLayer(args[0], out Side, out Layer);
                
                GerberTransposer.Transform(log, filename, outfile, dx, dy, cx, cy, angle);

               var  lines = PolyLineSet.SanitizeInputLines(System.IO.File.ReadAllLines(args[0]).ToList());
                System.IO.File.WriteAllLines(args[0] + "sanit.txt", lines);

                Gerber.SaveGerberFileToImage(log, outfile, outfile + "_render.png", 200, Color.Black, Color.White);

            }
        }
    

开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:37,代码来源:GerberMover.cs

在RotateFile()方法中,File的代码示例类中的ReadAllLines的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

本文中的File.ReadAllLines方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。