小编Mas*_*Net的帖子

如何在 Visual Studio 2015 中查看 CommandLineParser 解析错误?

我试图查看使用CommandLineParser 包和 Visual Studio Professional 2015(更新 3)解析命令行参数时发生的错误。这是我正在使用的代码:

using System;
using System.IO;

namespace SampleParser
{
    class Program
    {
        static void Main(string[] args)
        {
            // Set the CommandLineParser configuration options.
            var commandLineParser = new CommandLine.Parser(x =>
            {
                x.MutuallyExclusive = true;
                x.HelpWriter = Console.Error;
                x.IgnoreUnknownArguments = false;
            });

            // Parse the command-line arguments.
            var options = new CommandLineOptions();
            var optionsAreValid = commandLineParser.ParseArguments(args, options);

            if (!optionsAreValid)
            {
                return;
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我期待看到一些有关导致optionsAreValid设置为false的问题的有用信息出现在Debug > Windows > Output …

c# command-line-parser visual-studio-2015

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

C#和反思

我是C#的全新手,虽然没有编程,所以如果我混淆了一点,请原谅我 - 这完全是无意的.我编写了一个名为"API"的相当简单的类,它有几个公共属性(访问器/ mutator).我还编写了一个测试控制台应用程序,它使用反射来获取类中每个属性的名称和类型的字母顺序列表:

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using MyNamespace;      // Contains the API class

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hi");

            API api = new API(1234567890, "ABCDEFGHI");
            Type type = api.GetType();
            PropertyInfo[] props = type.GetProperties(BindingFlags.Public);

            // Sort properties alphabetically by name.
            Array.Sort(props, delegate(PropertyInfo p1, PropertyInfo p2) { 
                return p1.Name.CompareTo(p2.Name); 
            });

            // Display a list of property names and types.
            foreach (PropertyInfo propertyInfo in type.GetProperties())
            {
                Console.WriteLine("{0} [type = {1}]", propertyInfo.Name, …
Run Code Online (Sandbox Code Playgroud)

.net c# oop reflection

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

使用C#lambdas组合List <int>和int

我有以下Pair对象列表:

var listOfPairs = new List<Pair<int, List<int>>>() {
    new Pair<int, List<int>>(30, new List<int>() {3, 6, 9}),
    new Pair<int, List<int>>(40, new List<int>() {4, 8, 12})
};
Run Code Online (Sandbox Code Playgroud)

我想以下列整数列表结束:

listOfPairs[0] = {30, 3, 6, 9};
listOfPairs[1] = {40, 4, 8, 12};
Run Code Online (Sandbox Code Playgroud)

我尝试了很多看似这样的小摆设,但无济于事:

var flattenedListOfPairs = listOfPairs.Select(pair => new List<int>(pair.First).AddRange(pair.Second));
Run Code Online (Sandbox Code Playgroud)

我认为我正在尝试做的事情是可能的,而我只是遗漏了一些东西.

c# lambda

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

C#和Base-to-Derived类铸造

我想将基类实例列表中的信息投影到派生类实例列表中,但我一直在运行异常.这是我正在尝试做的一个例子......我如何使它工作?

以下代码在http://ideone.com/CaXQS上,如果有帮助的话...提前感谢!

using System;
using System.Collections.Generic;

namespace AddingReversedNumbers
{
        public class MyDerivedClass : MyBaseClass, IMyInterface
        {
                public int InterfaceProperty { get; set; }
                public int DerivedClassProperty { get; set; }
                public List<int> DerivedClassList { get; set; }
        }

        public class MyBaseClass
        {
                public int BaseClassProperty { get; set; }
        }

        public interface IMyInterface
        {
                int InterfaceProperty { get; set; }
        }

        class Program
        {
                static void Main()
                {
                        //// This code works just fine.
                        //var derivedList = new …
Run Code Online (Sandbox Code Playgroud)

c# casting type-conversion

0
推荐指数
1
解决办法
1411
查看次数