C
C
CanLap2017-08-13 14:52:24
JavaScript
CanLap, 2017-08-13 14:52:24

How does variable initialization work here?

Good afternoon. I can't understand one thing. In normal compilation mode, the phrase "Constructor B" is printed once. However, if you start debugging in one place (indicated in the code), then the phrase is printed 3 times. Very curious why this is happening.
45e90185c5694c4ab04ccb1c140ba8fd.png

using System;
class Program
{
    static void Main()
    {
        Console.WriteLine("До вызова");
        Class_1.StaticMethod();
        Console.WriteLine("После вызова");

        Console.ReadKey();
    }
}
class Class_1 
{
    private Class_2 field = new Class_2();

    public static void StaticMethod()
    {           
        Console.WriteLine(new Class_1().field); // Флажок для отладки
    }       
}
class Class_2
{
    public Class_2()
    {    
        Console.WriteLine("Конструктор B");
    }
    public override string ToString()
    {
        return "Class_2";
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2019-04-03
@Gorlaks

1. Fetch works. Server side error. Check the server and learn how to work with the network tab in the developer panel.
2. In the variant with Fetch in the body, in your case, you need to pass URLSearchParams

const body = new URLSearchParams();

body.set('key', 'value');

fetch(url, {
  method: 'POST',
  headers: {
    'Accept': 'application/x-www-form-urlencoded;charset=UTF-8'
  },
  body,
}).then(...);

3. Better use something like axios for queries .
4. SPA, in a good way, should interact with the server via the REST API, and the data should be transmitted in JSON format. There 'x-www-form-urlencoded'shouldn't be any.
Forget jQuery. Read about CORS

D
Dmitry, 2019-04-03
@dimoff66

Apparently in the dataCanvas in the first case you are passing an array, you need the string ' param1=value1¶m2=value2 ' and using encodeURIComponent () for the values

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question