Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

Flags (or compiler options) are nothing but ordinary command line arguments passed to the compiler executable.

Assuming you are invoking g++ from the command line (terminal):
***
$ g++ -std=c++11 your_file.cpp -o your_program
***
or
***
$ g++ -std=c++0x your_file.cpp -o your_program
***
if the above doesn't work.
4 years ago
Create a function that you want the thread to execute, eg:
***
void task1(std::string msg)
{
std::cout << "task1 says: " << msg;
}
***
Now create the thread object that will ultimately invoke the function above like so:
***
std::thread t1(task1, "Hello");
***
(You need to #include to access the std::thread class)

The constructor's arguments are the function the thread will execute, followed by the function's parameters. The thread is automatically started upon construction.

If later on you want to wait for the thread to be done executing the function, call:

t1.join();
(Joining means that the thread who invoked the new thread will wait for the new thread to finish execution, before it will continue its own execution).
4 years ago
Use Enum.TryParse(String, T) (? .NET 4.0):
***
StatusEnum myStatus;
Enum.TryParse("Active", out myStatus);
***
It can be simplified even further with C# 7.0's parameter type inlining:
***
Enum.TryParse("Active", out StatusEnum myStatus);
***
4 years ago
***
public static object GetPropValue(object src, string propName)
{
return src.GetType().GetProperty(propName).GetValue(src, null);
}
***
Of course, you will want to add validation and whatnot, but that is the gist of it.
4 years ago
What's likely happening is that SignalData is indirectly changing the subscribers dictionary under the hood during the loop and leading to that message. You can verify this by changing
***
foreach(Subscriber s in subscribers.Values)
***
To
***
foreach(Subscriber s in subscribers.Values.ToList())
***
If I'm right, the problem will disappear.

Calling subscribers.Values.ToList() copies the values of subscribers.Values to a separate list at the start of the foreach. Nothing else has access to this list (it doesn't even have a variable name!), so nothing can modify it inside the loop.
4 years ago
As highlighted by Tilendor in Jon Skeet's answer, streams have a CopyTo method since .NET 4.
***
var fileStream = File.Create("C:\\Path\\To\\File");
myOtherObject.InputStream.Seek(0, SeekOrigin.Begin);
myOtherObject.InputStream.CopyTo(fileStream);
fileStream.Close();
***
Or with the using syntax:
***
using (var fileStream = File.Create("C:\\Path\\To\\File"))
{
myOtherObject.InputStream.Seek(0, SeekOrigin.Begin);
myOtherObject.InputStream.CopyTo(fileStream);
}
***
4 years ago
Public - If you can see the class, then you can see the method

Private - If you are part of the class, then you can see the method, otherwise not.

Protected - Same as Private, plus all descendants can also see the method.

Static (class) - Remember the distinction between "Class" and "Object" ? Forget all that. They are the same with "static"... the class is the one-and-only instance of itself.

Static (method) - Whenever you use this method, it will have a frame of reference independent of the actual instance of the class it is part of.
4 years ago
You can use String.Join. If you have a List then you can call ToArray first:
***
List names = new List() { "John", "Anna", "Monica" };
var result = String.Join(", ", names.ToArray());
***
In .NET 4 you don't need the ToArray anymore, since there is an overload of String.Join that takes an IEnumerable.
4 years ago
There is a limit to the size of data you can encrypt with the RSA encryption, KeySize - MinimumPadding. e.g. 256 bytes (assuming 2048 bit key) - 42 bytes (min OEAP padding) = 214 bytes (max plaintext size)

Replace your_rsa_key with your RSA key.
***
var provider = new System.Security.Cryptography.RSACryptoServiceProvider();
provider.ImportParameters(your_rsa_key);

var encryptedBytes = provider.Encrypt(
System.Text.Encoding.UTF8.GetBytes("Hello World!"), true);

string decryptedTest = System.Text.Encoding.UTF8.GetString(
provider.Decrypt(encryptedBytes, true));
***
4 years ago
TLDR: A promise has resolve and reject, doing a reject without a catch to handle it is deprecated, so you will have to at least have a catch at top level.
4 years ago
Just write this command in the VS Code terminal of your project and restart the project.
***
npm install rxjs-compat
***
You need to import the map operator by adding this:
***
import 'rxjs/add/operator/map';
***
4 years ago
You can achieve this using by a simple custom pipe.
***
import { Pipe, PipeTransform } from '@angular/core';
import { DatePipe } from '@angular/common';

@Pipe({
name: 'dateFormatPipe',
})
export class dateFormatPipe implements PipeTransform {
transform(value: string) {
var datePipe = new DatePipe("en-US");
value = datePipe.transform(value, 'dd/MM/yyyy');
return value;
}
}


{{currentDate | dateFormatPipe }}
***
Advantage of using a custom pipe is that, if you want to update the date format in future, you can go and update your custom pipe and it will reflect every where.
4 years ago