小编Nag*_*eep的帖子

在linq中使用out类型

可能重复:
LINQ:如果string可解析为int,则选择解析的int

这可能是一个基本问题,但我无法找到解决方法.我有一个字符串数组,我试图用整数解析它们.正如所料,我得到了格式异常.

我怎么能跳过"3a"并继续解析剩余的数组并使用Linq将整数存储到输出中?这是一种更好的方法还是不做练习?在这种情况下,请介绍一下如何使用TryParse

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] values = { "1", "2", "3a","4" };
            List<int> output = new List<int>();

            try{
                output = values.Select(i => int.Parse(i)).ToList<int>();
            }
            catch(FormatException)
            {
                foreach (int i in output)
                    Console.WriteLine(i);
            }

            foreach (int i in output)
                Console.WriteLine(i);

            Console.ReadLine();
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# linq

7
推荐指数
1
解决办法
239
查看次数

使用c#保存为PDF,Interop不在word文档中保存嵌入的pdf

背景:我正在尝试使用c#和Interop生成一个word文档.我成功地插入了表格,页眉,页脚,图表......大部分工作都很好.下一步,我希望将其转换为pdf.

流程改编:由于我使用的是word 2011和word 2007(安装saveaspdf插件之后),我使用"另存为"将文档保存为pdf,然后将文件类型保存为pdf.

引发的问题:我已使用以下代码成功地将pdf嵌入到我的文档中.

        Object oIconLabel = new FileInfo(file_path).Name;
        Object oFileDesignInfo = file_path;
        Object oClassType = "AcroExch.Document.7";
        Object oTrue = true;
        Object oFalse = false;
        Object oMissing = System.Reflection.Missing.Value;
        Object index = 0;
        Range r = d.Bookmarks.get_Item(ref eod).Range;

        r.InlineShapes.AddOLEObject(
            ref oClassType, ref oFileDesignInfo, ref oFalse, ref oTrue, ref oMissing,
            ref index, ref oIconLabel, ref oMissing);
Run Code Online (Sandbox Code Playgroud)

这里d是Document对象.现在,当我尝试将此word文档保存为pdf时,使用

 d.SaveAs(ref filename, ref filetype, ref oMissing, ref oMissing, ref oMissing, 
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, …
Run Code Online (Sandbox Code Playgroud)

c# pdf ms-word office-interop

3
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×2

.net ×1

linq ×1

ms-word ×1

office-interop ×1

pdf ×1