问题列表 - 第16646页

将CSV字符串解析为整数数组

我有一个文本框字段输入123,145,125我将这个字段分成一个整数数组.如果所有内容都被正确解析,则验证此字段是true还是false.

码:

private bool chkID(out int[] val) 
{
    char[] delimiters = new char[] { ',' };
    string[] strSplit = iconeID.Text.Split(delimiters);  


    int[] intArr = null;
    foreach (string s in strSplit) //splits the new parsed characters 
    {
        int tmp;
        tmp = 0;
        if (Int32.TryParse(s, out tmp))
        {
            if (intArr == null)
            {
                intArr = new int[1];
            }
            else
            {
                Array.Resize(ref intArr, intArr.Length + 1);
            }
            intArr[intArr.Length - 1] = tmp;
        }

        if (Int32.TryParse(iconeID.Text, out tmp))
        {
            iconeID.BorderColor = Color.Empty;
            iconeID.BorderWidth = Unit.Empty; …
Run Code Online (Sandbox Code Playgroud)

c# csv arrays int parsing

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

Haskell尾函数用于空列表

我有一个函数的问题,该函数应该只返回列表的尾部.函数是myTail,即使输入是空列表,也应该给出一个可用的结果.

我想了解所有3种方式:模式匹配,保护方程和条件表达式

这工作:

> myTail_pat :: [a] -> [a]

> myTail_pat (x:xs) = xs
> myTail_pat [] = []
Run Code Online (Sandbox Code Playgroud)

但是这个:

> myTail_guard (x:xs)   | null xs = []
>               | otherwise = xs
Run Code Online (Sandbox Code Playgroud)

给我错误:程序错误:模式匹配失败:myTail_guard []如何声明没有模式的函数?

谢谢.

haskell list tail

9
推荐指数
2
解决办法
6762
查看次数

为什么布尔比较中有3个相等的符号?

可能重复:
Javascript === vs ==:我使用哪个"相等"运算符是否重要?

为什么我最近看到很多javascript代码,其表达式如下所示:

if(val === "something")
Run Code Online (Sandbox Code Playgroud)

为什么"==="而不仅仅是"=="?有什么不同?我什么时候应该使用其中一种?

javascript syntax

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

jQuery:如何仅根据表头从表的列中选择值

我有一个带标题ID的表.我需要选择此标题下的所有字段.我无权访问源代码,并且此表中没有使用任何类.有关如何完成这项工作的任何想法?

jquery select cell

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

Java泛型:多个通用参数?

我想知道是否可以编写一个接受多种泛型类型的函数,如下所示:

public int void myfunction(Set<T> a, Set<T> b) {
    return 5;
}

Set<Integer> setA = new HashSet<Integer>();
Set<String> setB = new HashSet<String>();
int result = myfunction(setA, setB);
Run Code Online (Sandbox Code Playgroud)

那会有用吗?每个参数中的泛型是否意味着每个参数必须具有相同的通用类型T?

谢谢!

java generics parameters

63
推荐指数
4
解决办法
11万
查看次数

示例或用途解释EJB事务属性的案例

EJB事务属性(和注释)有一些很好的解释,例如,OpenEJB.

但有时当我试图用一些没有使用过很多交易资源的人来掩盖这一点时,我看到他们的眼睛开始茫然.

所以我的问题 - 你如何向祖母解释EJB交易属性?

  • 需要
  • RequiresNew
  • 强制性
  • 不支持
  • 支持
  • 决不

我在想一个人为的例子,类比或简洁的现实用例会有所帮助.

java transactions java-ee ejb-3.0

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

Mysql如何压扁结果集

我有一个存储过程将返回一个id列表.我想将该列表作为逗号分隔的字符串返回,即"1,2,3,4,5".

我知道我可以使用游标执行此操作但是有更简单的方法将结果集转换为扁平字符串吗?

mysql

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

un-submodule一个git子模块

如何取消子模块git子模块(将所有代码重新放入核心)?

就像"应该"我一样,如"最佳程序"......

git git-submodules

359
推荐指数
8
解决办法
8万
查看次数

需要帮助理解指针和各种其他C的东西

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct dict_pair {
  void *key;
  void *value;
  struct dict_pair *tail;
} dict;


dict* NewDictionary(void) {
  dict *dictionary = malloc(sizeof(dict)); //or we can malloc(sizeof(struct dict_pair))
  dictionary->tail = NULL;
}

//dict operations
void put(dict *dictionary, void *key, void *value) {
  //new pair
  dict *new_pair = malloc(sizeof(dict));
  new_pair->key = key;
  new_pair->value = value;
  //chaining
  new_pair->tail = NULL;
  dict *last_node = dictionary;
  while (last_node->tail != NULL) {
    last_node = last_node->tail;
  }

  last_node->tail = new_pair;
}

void* get(dict …
Run Code Online (Sandbox Code Playgroud)

c

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

扩展方法有什么好处?

可能重复:
您找到了扩展方法的哪些优点?

好吧,首先,我意识到这听起来有争议,但我并不是说是对抗性的.出于好奇心(或许拼图是一个更好的词),我问一个严肃的问题.

为什么扩展方法引入.NET?它们提供了什么好处,除了让事情看起来很好(并且"好",我的意思是"看似像实例方法")?

对我来说,使用像这样的扩展方法的任何代码:

Thing initial = GetThing();
Thing manipulated = initial.SomeExtensionMethod();
Run Code Online (Sandbox Code Playgroud)

是误导,因为它暗示这SomeExtensionMethod是一个实例成员Thing,误导开发人员相信(至少作为一种直觉......你可能会否认它,但我肯定已经注意到这一点)(1)SomeExtensionMethod可能是有效实施的, (2)因为SomeExtensionMethod实际上它看起来像是课堂的一部分,Thing如果Thing在未来的某个时候进行修改,它肯定会保持有效(只要作者Thing知道他/她在做什么).

但事实是,扩展方法无法访问受保护的成员或他们正在扩展的类的任何内部工作,因此它们与任何其他静态方法一样容易破坏.

我们都知道以上很容易:

Thing initial = GetThing();
Thing manipulated = SomeNonExtensionMethod(initial);
Run Code Online (Sandbox Code Playgroud)

我来说,这似乎更多,因为缺乏一个更好的词,诚实.

我错过了什么?为什么存在扩展方法?

.net c# extension-methods static-methods

4
推荐指数
2
解决办法
1992
查看次数