小编Har*_*9pl的帖子

如何在java中创建FileFilter?

喜欢在标题中如何过滤到.txt文件?

我写了这样的东西,但它有错误:(

 private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        JFileChooser chooser = new JFileChooser();
        int retval = chooser.showOpenDialog(null);

        String yourpath = "E:\\Programy Java\\Projekt_SR1\\src\\project_sr1";
        File directory = new File(yourpath);
        String[] myFiles;
        FilenameFilter filter = new FilenameFilter() {
        public boolean accept(File directory, String fileName) {
            return fileName.endsWith(".txt");
        }
        };
        myFiles = directory.list(filter);


        if(retval == JFileChooser.APPROVE_OPTION)
        {
            File myFile = chooser.getSelectedFile();
        }
Run Code Online (Sandbox Code Playgroud)

java filefilter

39
推荐指数
4
解决办法
15万
查看次数

在#endregion自动创建具有相同名称的#region

我想知道是否有办法制作#region Some Region #endregion Some Region.如果没有办法做到这一点那么也许Resharper可能吗?

希望很清楚我在这里想要实现的目标.

编辑:

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
    <Header>
        <Title>#region</Title>
        <Shortcut>#region</Shortcut>
        <Description>Code snippet for #region</Description>
        <Author>Microsoft Corporation</Author>
        <SnippetTypes>
            <SnippetType>Expansion</SnippetType>
            <SnippetType>SurroundsWith</SnippetType>
        </SnippetTypes>
    </Header>
    <Snippet>
        <Declarations>
            <Literal>
                <ID>name</ID>
                <ToolTip>Region name</ToolTip>
                <Default>MyRegion</Default>
            </Literal>
        </Declarations>
        <Code Language="csharp"><![CDATA[#region $name$
    $selected$ $end$
#endregion $name$]]>
        </Code>
    </Snippet>
</CodeSnippet>
</CodeSnippets>
Run Code Online (Sandbox Code Playgroud)

第二次编辑: 它是有效的,但只有当我制作插入片段时.从intellisense这使用其他一些片段我猜.

那么有没有办法从intellisense添加我的区域而不是插入片段菜单?

.net c# resharper visual-studio code-snippets

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

如何在C#中乘以两个矩阵?

就像在标题中描述的那样,Microsoft框架中是否有一些库允许将两个矩阵相乘或者我必须编写自己的方法来执行此操作?//我现在已经得到了答案

第二个问题:我使用MultiplyMatrix方法编写了这个多类,但它不能像我想的那样工作.谁能帮忙告诉我哪里弄错了?

class multi
    {
        public void MultiplyMatrix(double[,] _A, double[,] _B, int _n, int _m, int _r)
        {
            int n, m, r;
            double si;
            n = _n;
            m = _m;
            r = _r;
            double[,] A = new double[n, m];
            double[,] B = new double[m, r];
            double[,] C = new double[n, r];
            A = _A;
            B = _B;
            try
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < r; j++)
                    {
                        si …
Run Code Online (Sandbox Code Playgroud)

c# math

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

获取只有字符串的嵌套枚举的类型?

我正在尝试做Typeenum是嵌套Class只有该枚举器的名称作为字符串.

例:

public static class MyClassWithEnumNested
{
     public enum NestedEnum
     {
         SomeEnum1,
         SomeEnum2,
         SomeEnum3
     }
}
Run Code Online (Sandbox Code Playgroud)

我需要得到

Type type = //what shall I write here?
Type type = Type.GetType("MyClassWithEnumNested.NestedEnum");//that doesn't work
Run Code Online (Sandbox Code Playgroud)

有没有办法Type在运行时获得它?

提前致谢:)

c# enums runtime

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

jQuery检查检查哪个radiobutton

我有2个radiobutton和1个radcombobox

<asp:RadioButton ID="cbxYes" Width="60" Height="30" runat="server" GroupName="proffesional" OnCheckedChanged="cbxYes_CheckedChanged" />
<asp:RadioButton ID="cbxNo" runat="server" Width="60" Height="30" GroupName="proffesional" Checked="true" OnCheckedChanged="cbxNo_CheckedChanged" />
<telerik:RadComboBox ID="dblSelect" EnableEmbeddedSkins="false" BackColor="Black" ForeColor="#d8d8d8" runat="server" Width="200" Height="30" ></telerik:RadComboBox>
Run Code Online (Sandbox Code Playgroud)

.不要使用clientidmode=static,我想显示或隐藏radcombobox根据检查radiobutton.

我写了这段代码:

<script type="text/javascript">
$(document).load(function () {
    var dropdown = $('#<%= dblSelect.ClientID%>');
    var radio1 = $('#<%= cbxYes.ClientID%>');
    var radio2 = $('#<%= cbxNo.ClientID%>');
    if ((radio1.is(':checked').val()) == 'true') {
        dropdown.is(':visible').val() = 'true';
    };
    if((radio2.is(':checked').val() == 'false'){
        dropdown.is(':visible').val() = 'false';
    };
});
</script>
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

提前致谢 :)

asp.net jquery

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

如何在字符串数组上使用Sum - LINQ?

如何用LINQ Sum方法对字符串数组求和?

我有一个字符串,看起来像: "1,2,4,8,16"

我试过了:

string myString = "1,2,4,8,16";
int number = myString.Split(',').Sum((x,y)=> y += int.Parse(x));
Run Code Online (Sandbox Code Playgroud)

但它说不能Parse输入int类型的类型?

我不想使用foreach循环来对这些数字求和.

c# linq arrays parsing sum

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

两个方法与ref对象par和没有?有什么区别?

我想知道以下方法在引用对象参数方面的区别是什么:

public void DoSomething(object parameter){}
Run Code Online (Sandbox Code Playgroud)

public void DoSomething(ref object parameter){}
Run Code Online (Sandbox Code Playgroud)

我是否应该ref object parameter在我想要更改引用的情况下使用object不覆盖同一引用中的对象?

c# ref

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

如何用反射获取枚举值的所有描述?

所以我需要List<string>从我的enum

到目前为止,这是我所做的:

枚举定义

    [Flags]
    public enum ContractorType
    {
        [Description("Recipient")]
        RECIPIENT = 1,
        [Description("Deliver")]
        DELIVER = 2,
        [Description("Recipient / Deliver")]
        RECIPIENT_DELIVER = 4
    }
Run Code Online (Sandbox Code Playgroud)

HelperClass与方法来做我需要的:

public static class EnumUtils
{
    public static IEnumerable<string> GetDescrptions(Type enumerator)
    {
        FieldInfo[] fi = enumerator.GetFields();

        List<DescriptionAttribute> attributes = new List<DescriptionAttribute>();
        foreach (var i in fi)
        {
            try
            {
                yield return attributes.Add(((DescriptionAttribute[])i.GetCustomAttributes(
                    typeof(DescriptionAttribute),
                    false))[0]);
            }
            catch { }
        }
        return new List<string>{"empty"};
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,在我yield重视的那一行中,我得到了一个NullReferenceException。我错过了什么?语法对我来说似乎还不错,但也许我忽略了某些内容?

编辑: 我在这里使用.net Framework 4.0。

c# reflection ienumerable enums custom-attributes

5
推荐指数
3
解决办法
9290
查看次数

按customAttribute的值排序对象的属性

我正在尝试做的是wirte linq表达式,它允许我List<PropertyInfo>通过Custom属性命令我的某个对象,例如:

public class SampleClass{

   [CustomAttribute("MyAttrib1",1)]
   public string Name{ get; set; }
   [CustomAttribute("MyAttrib2",1)]
   public string Desc{get;set;}
   [CustomAttribute("MyAttrib1",2)]
   public int Price{get;set;}
}
Run Code Online (Sandbox Code Playgroud)

CustomAttribute.cs:

public class CustomAttribute: Attribute{
    public string AttribName{get;set;}
    public int Index{get;set;}
    public CustomAttribute(string attribName,int index)
    {
        AttribName = attribName;
        Index = index;
    }
}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我能够从我的类中获取名为SampleClass的所有属性:

List<PropertyInfo> propertiesList = new List<PropertyInfo>((IEnumerable<PropertyInfo>)typeof(SampleClass).GetProperties());
Run Code Online (Sandbox Code Playgroud)

到目前为止,我尝试对此进行排序propertiesList(这顺便说一下):

var sortedPropertys = propertiesList
            .OrderByDescending(
                (x, y) => ((CustomAttribute) Attribute.GetCustomAttribute((PropertyInfo) x, typeof (CustomAttribute))).AttribName 
                .CompareTo((((CustomAttribute) Attribute.GetCustomAttribute((PropertyInfo) y, typeof (CustomAttribute))).AttribName ))
            ).OrderByDescending(
                (x,y)=>((CustomAttribute) Attribute.GetCustomAttribute((PropertyInfo) x, typeof …
Run Code Online (Sandbox Code Playgroud)

c# linq reflection linq-to-objects c#-4.0

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

MVC和jQuery datepicker

我正在尝试将datepicker应用于具有class属性equals的文本框中datepicker.

所以我这样做: _Layout.cshtml

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title</title>
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
    <script src="@Url.Content("~/Scripts/jquery-2.0.2.js")" 
    type="text/javascript"></script>
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.core.css")" 
    rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" 
    rel="stylesheet"  type="text/css" />
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.theme.css")" 
    rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-ui-1.10.3.js")" 
    type="text/javascript"></script>

</head>
<body>
    <header>
        <div class="content-wrapper">
            <div class="float-right">
                <nav>
                    <ul id="menu">
                        <li>@Html.ActionLink("Home", "Index", "Home")</li>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </header>
    <div id="body">
        @RenderSection("featured", required: false)
        <section class="content-wrapper main-content clear-fix">
            @RenderBody()
        </section>
    </div> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc jquery-ui jquery-ui-datepicker asp.net-mvc-4

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