我知道有关于堆栈溢出的一些问题已经存在,但我没有找到任何回答我的具体问题.我来自java开发背景,从不打扰使用get; 组; 从C#到现在的方法.
我有以下代码
class Test
{
public int test { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在我的主要功能中,我可以声明一个新的测试和使用t.Test = 5,并且工作正常; 但是,当我切换public到private我无法访问我的获取; 并设定; 方法......但是当我使用时(与Java类似的方法)
class Test
{
private int test;
public int getTest()
{
return this.test;
}
public void setTest(int test)
{
this.test = test;
}
}
Run Code Online (Sandbox Code Playgroud)
我对设计理念感到困惑.在C#中我应该不再使用私有变量(只有在类内部使用时才将其设为私有)并将它们全部公开并使用私有get; 私人集; 控制可访问性?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Threads
{
class Program
{
static void Main(string[] args)
{
Action<int> TestingDelegate = (x321) => { Console.WriteLine(x321); };
int x123 = Environment.ProcessorCount;
MyParallelFor(0, 8, TestingDelegate);
Console.Read();
}
public static void MyParallelFor(int inclusiveLowerBound, int exclusiveUpperBound, Action<int> body)
{
int size = exclusiveUpperBound - inclusiveLowerBound;
int numProcs = Environment.ProcessorCount;
int range = size / numProcs;
var threads = new List<Task>(numProcs);
for(int p = 0; p < numProcs; …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个以列表为例的函数
let list = [5;23;29;1]
let x = max list // This will return 2 because 29 will be the max value and it's "indexed" at position 2
Run Code Online (Sandbox Code Playgroud)
我不确定如何编写这个max函数
由于我的列表只包含四个元素,我目前有一些这样的代码
let list = (1, newMap1 |> getScore) :: (2, newMap2 |> getScore) :: (3, newMap3 |> getScore) :: (4, newMap4 |> getScore) :: []
Run Code Online (Sandbox Code Playgroud)
我认为这是一个可怕的方法,但我仍然坚持如何(x, _)在找到最大值后返回(_, y).我对命令式方法非常有信心,但我很难理解如何在功能上做到这一点
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
open System
let highLowGame () =
let rng = new Random()
let secretNumber = rng.Next() % 100 + 1
let rec highLowGameStep () =
printfn "Guess the secret number: "
let guessStr = Console.ReadLine()
let guess = Int32.Parse(guessStr)
match guess with
| _ when guess > secretNumber
-> (printfn "The secret number is lower")
highLowGameStep ()
| _ when guess = secretNumber
-> (printfn …Run Code Online (Sandbox Code Playgroud) 我有这样的数据集
1,2
3,4
5,6
7,8
9,0
Run Code Online (Sandbox Code Playgroud)
当我使用ReadAllLines读取它时,我得到一个字符串数组.到目前为止,我已经将字符串转换为包含字符串的列表数组
[["1";"2"];["3";"4"]... etc
Run Code Online (Sandbox Code Playgroud)
我需要最后一步才能得到这个 [[1;1;[1;4]... etc
我的代码现在:
module Data =
let load(path : string) (filename : string) =
System.IO.File.ReadAllLines(path + "\" + filename)
|> Array.toList
|> Seq.map (fun s -> s.Split [|','|] |> Array.toList)
|> Seq.map (fun s -> s |> Seq.map System.Int32.Parse)
Run Code Online (Sandbox Code Playgroud)
这是我测试它时返回的内容
val it : seq<seq<int>> = seq [seq [1; 2]; seq [3; 4]; seq [5; 6]]
Run Code Online (Sandbox Code Playgroud)
我期待这样的事情
val zz : int list list = [[1; 2]; [3; 4]]
Run Code Online (Sandbox Code Playgroud) let J = (-1.0 * y) .* MatrixMath.log <| Activation.sigmoid (X * theta)
let J = (-1.0 * y) .* MatrixMath.log (Activation.sigmoid (X * theta))
Run Code Online (Sandbox Code Playgroud)
我有以下两组代码与前者给出一个编译错误说"这个功能需要太多的争论",但后者工作正常.
我认为管道向后运营商的目标主要是改变我正在尝试做的评估顺序.
如何在不使用括号的情况下编写表达式?
编辑:
MatrixMath.log就是这么做的
type MatrixMath =
static member log X = X |> Matrix.map log
static member log X = X |> Vector.map log
Run Code Online (Sandbox Code Playgroud) class Thread1_8
{
static int shared_total;
static int thread_count;
static readonly object locker = new object();
static void Main()
{
int[,] arr = new int[5, 5] { { 1,2,3,4,5}, {5,6,7,8,9}, {9,10,11,12,13}, {13,14,15,16,17}, { 17,18,19,20,21} };
for(int i = 0; i < 5; i++)
{
new Thread(() => CalcArray(i, arr)).Start();
}
while(thread_count < 5)
{
}
Console.WriteLine(shared_total);
}
static void CalcArray(int row, int[,] arr)
{
int length = arr.GetLength(0);
int total = 0;
for(int j = 0; j < length; j++) …Run Code Online (Sandbox Code Playgroud) 我有一个界面
public interface HistoryDao<B extends UpdatableRecord<B>, H extends UpdatableRecord<H>> extends TableDao<H>{
default void saveHistoryForIds(List<Integer> ids) {
HashMap<? extends TableField<H, ? extends TableField<H, ? extends Serializable>>, ? extends TableField<B, ? extends TableField<B, ? extends Serializable>>> mappings = setUpHistoryMapping();
List<? extends TableField<H, ? extends Serializable>> tableFields = new ArrayList<>(mappings.keySet());
ArrayList<H> hs = new ArrayList<>();
jooq()
.insertInto(table(), tableFields);
}
HashMap<? extends TableField<H, ? extends TableField<H, ? extends Serializable>>, ? extends TableField<B, ? extends TableField<B, ? extends Serializable>>> setUpHistoryMapping();
}
Run Code Online (Sandbox Code Playgroud)
(TableDao是一个界面,但它不是非常重要)
在我的具体课程中,我尝试实施
MyClassHere implements …Run Code Online (Sandbox Code Playgroud) 我可以做一个GET请求,但我似乎无法获得POST请求.
这些是我的路线
article_path GET /api/articles Lxphnx.ArticleController :index
article_path GET /api/articles/:id Lxphnx.ArticleController :show
article_path POST /api/articles Lxphnx.ArticleController :create
article_path PATCH /api/articles/:id Lxphnx.ArticleController :update
PUT /api/articles/:id Lxphnx.ArticleController :update
article_path DELETE /api/articles/:id Lxphnx.ArticleController :delete
Run Code Online (Sandbox Code Playgroud)
除了使用mix phoenix.gen.json之外,我还没有碰过任何东西.这个项目只是一个API,因此我在创建项目时也使用了--no-brunch --no-html.
控制器:
defmodule Lxphnx.ArticleController do
use Lxphnx.Web, :controller
alias Lxphnx.Article
def index(conn, _params) do
articles = Repo.all(Article)
render(conn, "index.json", articles: articles)
end
def create(conn, %{"article" => article_params}) do
changeset = Article.changeset(%Article{}, article_params)
case Repo.insert(changeset) do
{:ok, article} ->
conn
|> put_status(:created)
|> put_resp_header("location", article_path(conn, :show, article))
|> …Run Code Online (Sandbox Code Playgroud) 我目前有 Angular 2 前端和 Phoenix 后端。由于某种原因,我可以很好地执行 GET 请求。在凤凰城我有代码endpoint.ex
plug Corsica, origins: "*"
Run Code Online (Sandbox Code Playgroud)
这允许我执行 GET 请求,但是,当我尝试将 POST 请求发送到同一地址时,我的后端会吐出错误
Invalid preflight CORS request because the header "content-type" is not in :allow_headers
Run Code Online (Sandbox Code Playgroud)
我不确定是否需要从前端发送某些内容,或者是否需要从后端启用某些内容。
for i = 1:p
X_poly(:, i) = X .^ i;
end
Run Code Online (Sandbox Code Playgroud)
迭代1:
-15.9368 0 0 0 0 0 0 0
-29.1530 0 0 0 0 0 0 0
36.1895 0 0 0 0 0 0 0
37.4922 0 0 0 0 0 0 0
-48.0588 0 0 0 0 0 0 0
-8.9415 0 0 0 0 0 0 0
15.3078 0 0 0 0 0 0 0
-34.7063 0 0 0 0 0 0 0
1.3892 0 0 0 …Run Code Online (Sandbox Code Playgroud)