小编fre*_*tje的帖子

如何使用InvariantCulture仅渲染某些特定的模型字段,而其余的则继续使用用户文化?

我在asp.net mvc视图上有几个隐藏的输入.它们的值包含类型的对象double.我希望它们能够被渲染,InvariantCulture因为它们习惯于被提供给客户端上的api(谷歌地图).就像现在一样,它们以逗号(,)作为小数分隔符进行渲染,而api则希望将点(.)作为小数分隔符.

最好的解决方案是,如果我可以DisplayFormat在模型的属性上的数据注释属性中指定文化,但我认为这不可能:

public class Position
{
    [DisplayFormat(DataFormatString="{0:G}, CultureInfo.InvariantCulture")]
    public double Latitude;
    ...
}
Run Code Online (Sandbox Code Playgroud)

我也不能在我的方法中设置CurrentCultureto ,因为屏幕上还有其他值必须在适当的用户文化中.InvariantCultureApplication_Start

那么,有没有办法暂时改变当前的文化,就在我Html.HiddenFor(Model => Model.Latitude)为特定属性做一个之前,然后重置它?

或者还有另一种更好的方法吗?什么是最佳做法?

c# asp.net-mvc formatting culture render

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

<img rel="nofollow noreferrer" src ="">是否会影响性能?

我只是想知道是否<img src="">在asp.net中伤害了性能?如果是,那么如何,以及什么是更好的解决方案?

编辑

我想补充一些细节: - 如果开发人员错过了src标签或服务器中缺少图像(例如服务器中缺少a.jpg)

<img src="Images/a.jpg">
Run Code Online (Sandbox Code Playgroud)

编辑

我问了这个问题,因为最近我遇到了一个问题,我们的页面只是因为服务器中缺少fav.ico而导致双重后退.

html asp.net

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

5
推荐指数
2
解决办法
1179
查看次数

编组从C++到C#的结构数组?

在我的C#代码中,我正在尝试从遗留C++ DLL中获取结构数组(代码我无法更改).

在该C++代码中,结构定义如下:

struct MyStruct
{
    char* id;
    char* description;
};
Run Code Online (Sandbox Code Playgroud)

我正在调用的方法(get_my_structures)返回一个指向MyStruct结构数组的指针:

MyStruct* get_my_structures()
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

还有另一种方法可以返回结构的数量,因此我知道返回了多少结构.

在我的C#代码中,我已经定义了MyStruct:

[StructLayout(LayoutKind.Sequential)]  
public class MyStruct
{
  [MarshalAsAttribute(UnmanagedType.LPStr)]    // <-- also tried without this
  private string _id;
  [MarshalAsAttribute(UnmanagedType.LPStr)]
  private string _description;
}
Run Code Online (Sandbox Code Playgroud)

互操作签名如下所示:

[DllImport("legacy.dll", EntryPoint="get_my_structures")]
public static extern IntPtr GetMyStructures();
Run Code Online (Sandbox Code Playgroud)

最后,获取MyStruct结构数组的代码如下所示:

int structuresCount = ...;
IntPtr myStructs = GetMyStructures();
int structSize = Marshal.SizeOf(typeof(MyStruct));    // <- returns 8 in my case
for (int i = 0; i < structuresCount; i++)
{
    IntPtr data = …
Run Code Online (Sandbox Code Playgroud)

.net c# c++ interop marshalling

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

我实施KMP算法有什么问题?

static void Main(string[] args)
{
    string str = "ABC ABCDAB ABCDABCDABDE";//We should add some text here for 
                                           //the performance tests.

    string pattern = "ABCDABD";


    List<int> shifts = new List<int>();

    Stopwatch stopWatch = new Stopwatch();

    stopWatch.Start();
    NaiveStringMatcher(shifts, str, pattern);
    stopWatch.Stop();
    Trace.WriteLine(String.Format("Naive string matcher {0}", stopWatch.Elapsed));

    foreach (int s in shifts)
    {
        Trace.WriteLine(s);
    }

    shifts.Clear();
    stopWatch.Restart();

    int[] pi = new int[pattern.Length];
    Knuth_Morris_Pratt(shifts, str, pattern, pi);
    stopWatch.Stop();
    Trace.WriteLine(String.Format("Knuth_Morris_Pratt {0}", stopWatch.Elapsed));

    foreach (int s in shifts)
    {
        Trace.WriteLine(s);
    }

    Console.ReadKey();
}

static IList<int> NaiveStringMatcher(List<int> …
Run Code Online (Sandbox Code Playgroud)

c# string algorithm performance

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

如何检查组合框是下拉列表还是下拉列表?

有没有办法检索CComboBox的类型?

我需要知道它是"Dropdown"还是"Drop List".

我尝试过以下方法:

if (m_MyComboBox.GetStyle() & CBS_DROPDOWN)
   // do some stuff
Run Code Online (Sandbox Code Playgroud)

if (m_MyComboBox.GetStyle() & CBS_DROPDOWNLIST)
   // do some stuff
Run Code Online (Sandbox Code Playgroud)

但是无论CComboBox是下拉列表还是下拉列表,这两个表达式似乎都评估为TRUE.

c++ mfc combobox

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

如何在.NET中安装Windows服务?

我在.Net 2.0(C#)中创建了一个控制台应用程序,并希望创建一个将应用程序安装为Windows服务的安装程序.

我之前从未创建过安装程序,但我正在阅读有关该主题的一些文章.非常感谢那些在这方面有一定经验的建议或链接.

谢谢.

更新:我目前正在查看http://justinjmoses.wordpress.com/2008/03/27/visual-studio-2008-standard-vs-professional/,以解决Windows服务应用程序模板未包含在VS 2008标准.

Russ Taylor还有一个默认的Windows服务项目可从http://russtaylor.co.uk/2009/01/writing-a-windows-service-in-visual-studio-2008-standard/下载.

.net c# installer windows-services

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

简单的Javascript问题

当我第一次点击按钮时,一切正常,但第二次,没有任何反应.这是为什么?

<form name="alert"><input type="text" name="hour"><input type="text" name="min"><input type="button" value="ok" onclick="budilnik(this.form)">

<script type="text/javascript">
function budilnik(form)
{

budilnik=1;
min=form.min.value;
hour=form.hour.value;
alert (min+' '+hour+' '+budilnik);

}
</script>
Run Code Online (Sandbox Code Playgroud)

javascript forms button

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

为什么我的流被同行关闭?

我有以下控制台程序,用于侦听 ActiveMQ Stomp 服务器上的目标(队列或主题,这并不重要),并简单地将收到的消息记录到控制台:

\n\n
using System;\nusing Apache.NMS.Stomp;\nusing Apache.NMS;\nusing Apache.NMS.Util;\n\nnamespace StompTest\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            try\n            {\n                var connectionFactory = new ConnectionFactory("stomp:tcp://mybroker:61613");\n\n                var connection = connectionFactory.CreateConnection();\n                connection.ExceptionListener += new ExceptionListener(connection_ExceptionListener);\n                connection.Start();\n\n                var session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);\n\n                IDestination dest = SessionUtil.GetDestination(session, "queue://MyQueue");\n\n                var consumer = session.CreateConsumer(dest);\n                consumer.Listener += new MessageListener(consumer_Listener);\n\n                Console.ReadKey();\n            }\n            catch (NMSException ex)\n            {\n                Console.WriteLine("NMSException !! ==> " + ex.Message);\n            }\n        }\n\n        static void connection_ExceptionListener(Exception exception)\n        {\n            Console.WriteLine("Exception!! ==> " + exception.ToString());\n        }\n\n        static void consumer_Listener(IMessage …
Run Code Online (Sandbox Code Playgroud)

.net c# stomp nms apache-nms

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