小编Oli*_*bes的帖子

在一个列表中有更多不同类型的对象

是否可以在同一列表中添加更多不同类型的对象,我该如何做?

我有一个基类和三个子类,我希望所有子类对象在同一个列表中.

c# list base subclass object

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

随机数猜谜游戏

我正在做一个随机数猜测游戏,计算机认为是1-100之间的数字.然后它会询问你它是什么,并告诉你你是对还是错.但是,每当我调试时,由于某种原因它会说它高于或低于实际随机数.此外,它同时说出其中两个陈述.另外,我不知道怎么说这个人已经猜了多少次.这是我不成功的代码.

static void Main(string[] args) 
{
    Random random = new Random();

    int returnValue = random.Next(1, 100);
    int Guess = 0;

    Console.WriteLine("I am thinking of a number between 1-100.  Can you guess what it is?");

    while (Guess != returnValue)
    {
        Guess = Convert.ToInt32(Console.Read());

        while (Guess < returnValue)
        {
            Console.WriteLine("No, the number I am thinking of is higher than " + Guess + " .  Can you guess what it is?");
            Console.ReadLine();

        }
        while (Guess > returnValue)
        {
            Console.WriteLine("No, the number I …
Run Code Online (Sandbox Code Playgroud)

c# numbers

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

C#奇数列表行为

这可能有点像一个愚蠢的问题,但我似乎根本找不到任何关于这种行为的信息.

这是代码:

class Cars
{
    public int year = 0;
    public string make = " ";
    public string model = " ";

    public Cars()
    {
    }

    public Cars(int tYear, string tMake, string tModel)
    {
        year = tYear;
        make = tMake;
        model = tModel;
    }

    public string ConvertToString()
    {
        return year.ToString() + make + model;
    }
}

class Program
{
    Cars oneCar = new Cars();
    List<Cars> manyCars = new List<Cars>();

    public void Init()
    {
        manyCars.Add(new Cars(1993, "Nissan", "240SX"));
        manyCars.Add(new Cars(2001, "Isuzu", …
Run Code Online (Sandbox Code Playgroud)

c# pointers list

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

BinarySearch如何在两个邻居之间找到数组中的值?

我有一个排序数组double.目标是在Array中查找索引.其中包含<=搜索值的值.

例如,数组包含{0, 5, 12, 34, 100}索引范围为[0 .. 4]的数字.

搜索值= 25.我想得到指数= 2(出现的范围在12到34之间)

我不明白在这种情况下如何运行二进制搜索.

   public class MyComparer : IComparer<double>
    {
        public int Compare(double x, double y)
        {
            //<-------- ???
        }
    }

    public double[] spline_x;

    MyComparer cmpc = new MyComparer();
    int i=Array.BinarySearch(spline_x, x, cmpc);
Run Code Online (Sandbox Code Playgroud)

c# arrays algorithm find binary-search

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

WPF - Datatemplate未在listbox itemtemplate中应用

我试图在列表框中添加包含一些示例数据的datatemplatate,但它们似乎对我的dataTemplate的listboxitem没有影响,以下是使用的代码 -

<Page
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <Grid.Resources>
            <DataTemplate x:Key="test1">
                <TextBlock Background="Red">
                </TextBlock>
            </DataTemplate>
        </Grid.Resources>
        <ListBox ItemTemplate="{StaticResource test1}">
            <ListBoxItem>A</ListBoxItem>
            <ListBoxItem>B</ListBoxItem>
            <ListBoxItem>C</ListBoxItem>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"  ></StackPanel>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
    </Grid>
</Page>
Run Code Online (Sandbox Code Playgroud)

listboxitem的背景并没有变成红色,我知道我可以使用itemcontainerstyle实现类似的东西但是想知道为什么没有在这里应用datatemplate,

.net wpf

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

“PlotBackBrush”无法通过类“PlotSurface2D”在项目外部公开类型“IRectangleBrush”

我有一个界面

Public Interface IPlotSurface2D
   WriteOnly Property PlotBackBrush() As IRectangleBrush
End Interface
Run Code Online (Sandbox Code Playgroud)

这是实现接口的类

Public Class PlotSurface2D
    Implements IPlotSurface2D

    Public WriteOnly Property PlotBackBrush() As IRectangleBrush _
        Implements IPlotSurface2D.PlotBackBrush

        Set(value As IRectangleBrush)
            Me.plotBackBrush_ = DirectCast(value, IRectangleBrush)
            Me.plotBackColor_ = DirectCast(Nothing, Object)
            Me.plotBackImage_ = DirectCast(Nothing, Drawing.Bitmap)
        End Set
    End Property
End Class
Run Code Online (Sandbox Code Playgroud)

我收到以下编译错误:

错误 86“PlotBackBrush”无法通过类“PlotSurface2D”在项目外部公开类型“IRectangleBrush”。

我怎样才能解决这个问题?

vb.net inheritance interface

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

System.TypeLoadException:类型'OpenQA.Selenium.Appium.Service.AppiumCommandExecutor'中的方法'Dispose'

我的项目停止工作。我拥有所有nuget和appium服务器的最新版本。哪里有问题?我收到这样的错误:

信息:

OneTimeSetUp:System.TypeLoadException:程序集“ appium-dotnet-driver,Version = 3.0.0.2,Culture = neutral,PublicKeyToken = null”中类型'OpenQA.Selenium.Appium.Service.AppiumCommandExecutor'中的'Dispose'方法没有实施。**

protected AppiumDriver<AppiumWebElement> driver = null;
private DesiredCapabilities dc = new DesiredCapabilities();

public Driver()
{
    dc.SetCapability("reportDirectory", reportDirectory);
    dc.SetCapability("reportFormat", reportFormat);
    dc.SetCapability("testName", testName);
    dc.SetCapability("deviceName", AppConfigReader.DEVICE_NAME);
    dc.SetCapability("language", "en");
    dc.SetCapability("locale", "UK");
    dc.SetCapability("newCommandTimeout", 120);
    //dc.SetCapability("automationName", "UiAutomator2");
    dc.SetCapability(MobileCapabilityType.Udid, AppConfigReader.DEVICE_NAME);
    dc.SetCapability(AndroidMobileCapabilityType.AppPackage, AppConfigReader.APPLICATION_NAME);
    dc.SetCapability(AndroidMobileCapabilityType.AppActivity, "novacura.flow.client.android.SplashScreen");
    driver = new AndroidDriver<AppiumWebElement>(new Uri(AppConfigReader.HOST), dc);
}
Run Code Online (Sandbox Code Playgroud)

c# selenium webdriver appium

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

System.Data.SqlClient.SqlException: '''' 附近的语法不正确。

我正在尝试使用 ASP.NET 创建一个登录字段,它将从文本框字段中获取输入并根据我的数据库中的“用户”表检查它们。列是User IDPassword。但是一个错误

System.Data.SqlClient.SqlException: ''' 附近的语法不正确

使用登录表单时出现。我没有看到任何语法问题...

我是新手,所以如果错误很明显,请原谅!

public partial class Login_Page : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblErrorMessage.Visible = false;
        SqlConnection con = new SqlConnection("Data Source=JACKS-PC\\SQLEXPRESS;Initial Catalog=CBR;Integrated Security=True");
        con.Open();
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    { 
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "Data Source=JACKS-PC\\SQLEXPRESS;Initial Catalog=CBR;Integrated Security=True";
            con.Open();

            string userid = txtUsername.Text.Trim();
            string password = txtPassword.Text.Trim();

            SqlCommand cmd = new SqlCommand("select `user id`,`password` from user where `user id`='" + …
Run Code Online (Sandbox Code Playgroud)

c# sql-server asp.net-mvc visual-studio

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

Visual Studio 2019 数据源窗口不允许我添加数据库文件

我正在尝试将数据库连接到我的 C# Windows 窗体应用程序,但数据源窗口显示

所选项目不支持此窗口。

我怎样才能解决这个问题?我在服务器资源管理器中设置了数据连接。

sql database

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

创建 C# 类的对象有哪些不同的方法?

我在求职面试中被问到这个问题,但不确定 C# 中还有哪些其他选项可用于创建类的对象。我知道创建对象的基本方法。例如:我有一个名为“ClassName”的类,所以要创建对象,我可以使用

ClassName classNameObject = new ClassName();
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我还有哪些其他方法可以用来实例化一个类?提前致谢!

c# object

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