小编Cor*_*ane的帖子

无效的URI:无法解析主机名

我正在尝试构建Uri但是我无法处理坏的uri

我们有什么方法可以处理坏的uri

if (reviews[e.Item.ItemIndex].URL.ToString().Contains("http:"))
{
      oURI = new Uri(reviews[e.Item.ItemIndex].URL.ToString());
}
else 
{
   oURI = new Uri("http://"+ reviews[e.Item.ItemIndex].URL.ToString());
}
Run Code Online (Sandbox Code Playgroud)

其他部分因为坏的uri而出错了谢谢

c# error-handling uri

17
推荐指数
2
解决办法
7万
查看次数

Is there a difference between "double val = 1;" and "double val = 1D;"?

Is there a difference between the following two pieces of code?

class Test {

    public readonly double Val;

    public Test(bool src) {
        this.Val = src ? 1 : 0;
    }

}

class Test {

    public readonly double Val;

    public Test(bool src) {
        this.Val = src ? 1D : 0D;
    }

}
Run Code Online (Sandbox Code Playgroud)

I found that our code base uses the second way of writing.

.net c#

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

How to open the tablet-mode on-screen-keyboard in C#?

I want to start the new On-Screen-Keyboard (OSK) using code. You can find this one in the taskbar:

新OSK任务栏

(if not there you find it by right clicking the taskbar).

I have already tried the regular:

System.Diagnostics.Process.Start("osk.exe");
Run Code Online (Sandbox Code Playgroud)

But I want to start the other one (not in window mode). Here you see which OSK I want and which one not:

OSK wanted version distinction

How can I start that version? And how can I start it in a certain setting (if possible)?

c# on-screen-keyboard

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

当向 XAML 中的 TextBlock 添加新行时,将 ScrollViewer 滚动到 WPF 中的底部

我试图将垂直滚动条保留在底部(最新条目),但目前,滚动条只是停留在同一个位置,因此当内容被添加到字符串中时,滚动条会移动到顶部。

我知道我可以使用ServerScroll.ScrollToEnd()代码隐藏中的属性将栏移动到末尾。但是有没有办法用xaml自动做到这一点?(这样我就不必每次添加到字符串时都调用此属性)。

XAML

<ScrollViewer Name="ServerScroll"
              VerticalScrollBarVisibility="Auto">
    <TextBlock Name="serverConsole"
               Margin="5"
               Background="White"
               TextWrapping="Wrap"/>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)

代码隐藏

private void example_Click(object sender, RoutedEventArgs e)
{
    ServerConsole += "asdf\r\n";      // binded to TextBlock
    ServerScroll.ScrollToEnd();    
}
Run Code Online (Sandbox Code Playgroud)

c# wpf eventtrigger scrollviewer

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

有没有办法在调试时查看 UI 更新?

目前我正在尝试调试一些代码,其中我正在检查项目的可见性(.IsVisible()例如使用方法)。问题是,当我从一个断点跳到下一个断点或在行之间跳转时,数据显然发生了变化,但程序的 UI 似乎根本没有变化。这让我很难判断事物是否可见,我必须信任 Visual Studio。

有没有办法在调试时更新 UI,这样我也可以看到那里的变化?

.net c# wpf user-interface visual-studio

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

isin、str.contains 和 if 条件之间的区别?

我通常很困惑,如果我想用某些东西过滤数据框列项目,应该isin.str.contains或被if "aa" in df["column"]使用吗?

请告诉我在不同情况下使用哪些?

python dataframe

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

如何将我的 UIButton 标题绑定到我的 ViewModel

我想将UIButton标题绑定到BehaviorSubject<String>我的 ViewModel 中。我这样做Label如下:

//ViewModel
var fullName = BehaviorSubject<String?>(value: "")

//ViewController
vm.fullName.bind(to: fullNameLabel.rx.text).disposed(by: bag)
Run Code Online (Sandbox Code Playgroud)

有什么办法可以做到这一点吗?

mvvm ios swift rx-swift

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

如何在静态泛型方法中为 T 设置默认类型?

我正在使用我自己的自定义堆栈类,并且我正在尝试创建用于创建新堆栈(通用对象)的通用方法。我经常使用 int 类型的堆栈,只是偶尔需要其他类型的堆栈。我可以将 T 的默认类型设置为 int 吗?

这是方法:

public static Stack<T> newStack<T>(int length)
{
    Stack<T> s = new Stack<T>();
    for (int i = 0; i < length; i++)
    {
        Console.WriteLine("print num");
        string input = Console.ReadLine();
        T value = (T)Convert.ChangeType(input, typeof(T));
        s.Push(value);
    }
    return s;
}
Run Code Online (Sandbox Code Playgroud)

我想使用这样的方法:

newStack(5);//defult int type
Run Code Online (Sandbox Code Playgroud)

对于任何其他类型

newStack<string>(5)
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?谢谢。

c# generics

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

从动态类型创建泛型类的实例

是否可以创建动态派生类型的泛型类的实例。

Class GenericClass<T> {

}

Main()
{
    string inputtype = "classname, assemblyname";

    Type type = Type.GetType(inputtype);

    dynamic instance = Activator.CreateInstance(type);

    // Want to create a object of GenericClass<T> but I get compiletime errors.
    // Is it possible to do like below?

    GenericClass<instance> = new GenericClass<instance>();
}
Run Code Online (Sandbox Code Playgroud)

.net c# generics reflection

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

有人可以解释在此Python程序中*的用法吗?

if __name__ == '__main__':
    n = int(input())
    student_marks = {}
    for _ in range(n):
        name, *line = input().split()
        scores = list(map(float, line))
        student_marks[name] = scores
    query_name = input()
Run Code Online (Sandbox Code Playgroud)

有人可以*在上面的Python代码段中解释的用法吗?

python dictionary python-3.x

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