C# string reference type?

I know that “string” in C# is a reference type. This is on MSDN. However, this code doesn’t work as it should then: class Test { public static void Main() { string test = “before passing”; Console.WriteLine(test); TestI(test); Console.WriteLine(test); } public static void TestI(string test) { test = “after passing”; } } The output should … Read more

python list by value not by reference [duplicate]

This question already has answers here: How do I clone a list so that it doesn’t change unexpectedly after assignment? (21 answers) Closed 4 years ago. Let’s take an example a=[‘help’, ‘copyright’, ‘credits’, ‘license’] b=a b.append(‘XYZ’) b [‘help’, ‘copyright’, ‘credits’, ‘license’, ‘XYZ’] a [‘help’, ‘copyright’, ‘credits’, ‘license’, ‘XYZ’] I wanted to append value in list … Read more

Why is it discouraged to accept a reference to a String (&String), Vec (&Vec), or Box (&Box) as a function argument?

I wrote some Rust code that takes a &String as an argument: fn awesome_greeting(name: &String) { println!(“Wow, you are awesome, {}!”, name); } I’ve also written code that takes in a reference to a Vec or Box: fn total_price(prices: &Vec<i32>) -> i32 { prices.iter().sum() } fn is_even(value: &Box<i32>) -> bool { **value % 2 == … Read more

Why is ‘this’ a pointer and not a reference?

I was reading the answers to this question C++ pros and cons and got this doubt while reading the comments. programmers frequently find it confusing that “this” is a pointer but not a reference. another confusion is why “hello” is not of type std::string but evaluates to a char const* (pointer) (after array to pointer … Read more

Understanding exactly when a data.table is a reference to (vs a copy of) another data.table

I’m having a little trouble understanding the pass-by-reference properties of data.table. Some operations seem to ‘break’ the reference, and I’d like to understand exactly what’s happening. On creating a data.table from another data.table (via <-, then updating the new table by :=, the original table is also altered. This is expected, as per: ?data.table::copy and … Read more

How to reference generic classes and methods in xml documentation

When writing xml documentation you can use <see cref=”something”>something</see>, which works of course. But how do you reference a class or a method with generic types? public class FancyClass<T> { public string FancyMethod<K>(T value) { return “something fancy”; } } If I was going to write xml documentation somewhere, how would I reference the fancy … Read more