当前位置: 首页>>代码示例>>C#>>正文


C# MemoryStream.ToString方法代码示例

本文整理汇总了C#中MemoryStream.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.ToString方法的具体用法?C# MemoryStream.ToString怎么用?C# MemoryStream.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MemoryStream的用法示例。


在下文中一共展示了MemoryStream.ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MyMethod

    Func<string, string> MyMethod()
    {
        // If we have a high resource consumption resource, like IDisposable
        System.IO.Stream s = new MemoryStream();
        // then we should know how Garbage Collector works.
        
        // This "s" is of course defined in this MyMethod() and usually
        // Garbage Collector can dispose it when we exit the method.

        // But if "s" is captured to a function:
        Func<string, string> myfunc = y => y + s.ToString();
        // the GC can't dispose it before all the references to 
        // both MyMethod() and myfunc() are gone.

        // This may be not so obvious if the method is async or if I return it away from here:
        if (new Random().NextDouble() > 0.6) return myfunc;

        // So the point is this: when you do any lambda (not just Func<T>), 
        // you should know your captured parameters.
        // Avoid capturing disposables and large objects like "this".
        return h => h;
    }
开发者ID:Thorium,项目名称:LINQ-Tutorial,代码行数:22,代码来源:Lesson3-Functions.cs


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