小编Hei*_*del的帖子

C#中的Convert.ToDouble和Double.Parse

我想请教一下Convert.ToDouble,并Double.Parse在C#
当我写这篇文章的代码,它的确定

static void Main(string[] args)
    {
        double red;
        Console.Write("Red = ");
        red = Convert.ToDouble(Console.ReadLine());
    }
Run Code Online (Sandbox Code Playgroud)

但如果我试试

static void Main(string[] args)
    {
        double red;
        Console.Write("Red = ");
        red = Double.Parse(Console.ReadLine());
    }
Run Code Online (Sandbox Code Playgroud)

我从ReSharper那里得到警告'Possible 'null' assignment to entity marked with 'NotNull' attribute'
如何解决这个问题?

c# resharper

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

在C#中创建类复数

我尝试用两个不同的构造函数在C#中创建类复数,第一个构造函数采用实部和虚部,第二个构造函数采用模块和参数.

public class Complex
{
    public Complex() { }

    private Complex(double _re, double _im)
    {
        re = _re;
        im = _im;
    }

    public static double Complex_FromCartesian(double _re, double _im)
    {
        return new Complex(_re, _im);
    }

    public static double Complex_FromPolar(double _mod, double _arg)
    {
        var _re = _mod * Math.Cos(_arg);
        var _im = _mod * Math.Sin(_arg);
        return new Complex(_re, _im);
    }

    public static Complex operator +(Complex num1, Complex num2)
    {
        return new Complex(num1.re + num2.re, num2.im + num2.im);
    }

    public static …
Run Code Online (Sandbox Code Playgroud)

c#

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

Laravel Elixir路径

我使用Elixir编译我的较少文件

elixir(function(mix) {
mix.less([
    "../../../vendor/uikit/uikit/src/less/uikit.less",
    "main.less"
], 'public/css/style.css').version("public/css/style.css");
});
Run Code Online (Sandbox Code Playgroud)

然后我尝试使用css文件

<link rel="stylesheet" type="text/css" href="{{ elixir('css/style.css') }}">
Run Code Online (Sandbox Code Playgroud)

但我得到了结果 http://localhost:8080/build/css/style-a3ade8736f.css 404 (Not Found)

我使用XAMMP,所以我的网址看起来像 http://localhost:8080/ad/public/

当我尝试在css href中添加'piblic /'字样时,
<link rel="stylesheet" type="text/css" href="public/{{ elixir('css/style.css') }}">
我得到一个错误
http://localhost:8080/ad/public/public//build/css/style-a3ade8736f.css 404 (Not Found)

如何修复href?

laravel laravel-elixir

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

Laravel复选框始终保存为1

表单中有复选框

{!! Form::checkbox('is_explicit_content', '1', $post->is_explicit_content, ['id' => 'is_explicit_content']); !!} 
{!! Form::label('is_explicit_content', 'Explicit', ['class' => 'checkbox-label']) !!}
Run Code Online (Sandbox Code Playgroud)

模型

class Post extends Model
{
    protected $fillable = [
        'text',
        'is_explicit_content'
    ];
}
Run Code Online (Sandbox Code Playgroud)

但是值总是保存为1,我不明白为什么?如何解决?

laravel

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

JavaScript中的后缀和前缀增量

我只是好奇一件事.Javascript中的一个小例子

var a = 1;
a = a++;
console.log(a); // 1

var b = 1;
b = ++b;
console.log(b); // 2

var c = 1;
c += 1;
console.log(c); //2
Run Code Online (Sandbox Code Playgroud)

我理解为什么是这样工作的情况下,bc,但怎么样a?首先代码进行赋值a = a,实际值保持不变,但它应该(如我所见)增加并增加a每单位的值.但这没有发生.为什么?

javascript

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

在@ Html.TextAreaFor MVC 4中添加文本

我需要在我的表单中创建textarea字段

 <textarea class="img-shadow" cols="20" id="Message" name="Message" rows="2">Message</textarea>
Run Code Online (Sandbox Code Playgroud)

我写代码

  @Html.TextAreaFor(model => model.Message, new { @class = "img-shadow" })
Run Code Online (Sandbox Code Playgroud)

但我没有任何文字,我得到空文本区域

 <textarea class="img-shadow" cols="20" id="Message" name="Message" rows="2"></textarea>
Run Code Online (Sandbox Code Playgroud)

我该如何添加文字?

asp.net-mvc asp.net-mvc-4

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

在C#中检查整数是否为2的幂

我的计划有什么问题?

namespace ConsoleApplication1
{
class Program
{
    static void Main(string[] args)
    {
        bool check = isPowerOfTwo(255);
        Console.WriteLine(check);
        Console.ReadKey();
    }

    public bool isPowerOfTwo (uint x)
    {
        while (((x % 2) == 0) && x > 1)
        {
            x /= 2;
        }
        return (x == 1);
    } 
}
Run Code Online (Sandbox Code Playgroud)

}

我收到了错误

非静态字段,方法或属性需要对象引用.

c#

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

用C#在RGB中创建类颜色

我试图用C#在RGB中创建类Color,颜色(红色,绿色,蓝色)的值必须在范围[0,1]内.
这是我的代码

public class ColorRGB
    {
        private ColorRGB(double _red, double _green, double _blue)
        {
            Red = _red;
            Green = _green;
            Blue = _blue;
        }

        public static ColorRGB ColorRGB_RGBModel(double _red, double _green, double _blue)
        {
            return new ColorRGB(_red, _green, _blue);
        }

        public static ColorRGB ColorRGB_CMYModel(double _cyan, double _magenta, double _yellow)
        {
            var _red = 1 - _cyan;
            var _green = 1 - _magenta;
            var _blue = 1 - _yellow;
            return new ColorRGB(_red, _green, _blue);
        }

        public ColorRGB AddRGB(ColorRGB _secondColor)
        {
            return …
Run Code Online (Sandbox Code Playgroud)

c#

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

查找枚举中定义的项目总数 C#

为什么我的代码不起作用?

using System;

namespace Enum
{
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine(Test.FruitCount);
    }
}

public class Test
{
    enum Fruits { Apple, Orange, Peach }
    public const int FruitCount = Enum.GetNames(typeof(Fruits)).Length;
}
}
Run Code Online (Sandbox Code Playgroud)

我收到错误

无法解析符号“GetNames”

为什么?如何解决这个问题?

c#

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

反应为选择设置默认值

这是我的SearchForm.js 类,period是一个选择列表

import React from 'react';
import ReactDOM from 'react-dom';
import axios from 'axios';

class SearchForm extends React.Component {

        constructor(props) {
            super(props)

            this.state = {
                position: '',
                area: '',
                period: '',
                experience: {
                    type: Array,
                    default: () => []
                }
            }
            this.handlePeriodChange = this.handlePeriodChange.bind(this);
        }


        handlePeriodChange(e) {
            this.setState({
                [e.target.name]: e.target.value
            });
        }      

        render() {
            return ( <
                form className = 'form search-form'
                onSubmit = {
                    this.handleSubmit
                } >
                <
                div className = "form-row" >

                    <
                    div className …
Run Code Online (Sandbox Code Playgroud)

reactjs

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