reference

C# Accessing a dictionary from another class is not working

偶尔善良 提交于 2019-12-24 00:49:35
问题 I'm fairly new to C# and have been trying to learn for the last 3 days. I am curious as to why the below code is not working properly? I get the following error: Object reference not set to an instance of an object. when I try to call data.dOffsets["roomtargets"]. However, calling data.sProcessName does work without any error.. I have two classes/files. The program.cs: class Program { public static Data data = new Data(); static void Main(string[] args) { Console.WriteLine("data.sProcessName:

&$variable in PHP

喜你入骨 提交于 2019-12-24 00:35:56
问题 I have been looking through wordpress's core files and stumbled across this piece of code, I noticed it had an ampersand before a variable name and after an =. I have tried searching this and came across this from the PHP manual and it doesn't explain it well, or I'm looking at the wrong one! I also saw that it is used to modify a variable outside of the method where it is being used, but, thats what a variable is there for, to be modified so if this is correct how would one use it? function

Cannot reference a field before it is * defined" error

落爺英雄遲暮 提交于 2019-12-23 21:10:44
问题 public class Test1 { static{ a=20; // System.out.println(a); //Line 4 } static int a=getA(); private static int getA() { return 10; } public static void main(String[] args) { System.out.println(a); } } Why it showing error ?but if remove the Line working fine ? 回答1: It works if you declare a before the static initializer: public class Test1 { static int a=getA(); static{ a=20; System.out.println(a); } private static int getA() { return 10; } public static void main(String[] args) { System.out

Why does reference = null not affect the referenced object?

不羁岁月 提交于 2019-12-23 20:35:18
问题 I know this works, but I don't know why or the reasoning behind why it was made to work this way: var foo = [5, 10]; var bar = foo; console.log(foo); //[5, 10] console.log(bar); //[5, 10] bar[0] = 1; console.log(foo); //[1, 10] bar = null; console.log(foo); //[1, 10] I would have expected not just bar to become null, but foo as well. I'd love some help understanding this. 回答1: The difference is between rebinding and mutating operations. bar[0] = 1 is mutating; it affects the object that bar

Why do I get this error creating & returning a new struct?

浪子不回头ぞ 提交于 2019-12-23 19:40:32
问题 I get an error when I compile this code: using System; public struct Vector2 { public event EventHandler trigger; public float X; public float Y; public Vector2 func() { Vector2 vector; vector.X = 1; vector.Y = 2; return vector; // error CS0165: Use of unassigned local variable 'vector' } } hi! The compiler says: "Use of unassigned local variable 'vector'" and points to the return value. It looks to me that Vector2 become a reference type (without the event member it acts normally). What is

Passing by reference vs. passing by value

旧街凉风 提交于 2019-12-23 18:53:35
问题 <?php function sum($y) { $y = $y + 5; } $x = 5; sum($x); echo $x; ?> So I have this code. The questions are: What does it output? The answer: 5. How do I make it to output 10? The answer: sum(&$x). The problem is that I don't understand why the answer to the first question is 5. When you make sum($x), shouldn't it replace the function with $x, so $x= 5+5=10? Why the answer is 5? I really don't understand. Someone explaind me something related to pointers and the adress, but I didn't

C++ reference to nowhere [closed]

橙三吉。 提交于 2019-12-23 18:23:21
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . Thinking of this question Why can I initialize reference member with data member before initializing the data member? as well as this Why is initialization of a new variable by itself valid? following strange code came to my mind: int main() { int &ri = ri; ri = 0; } This code

Ternary operator not working with reference variables in PHP [closed]

吃可爱长大的小学妹 提交于 2019-12-23 18:17:03
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . Why isn't this working? $a = 'FOO'; $foo = $a ? &$a : 'whatever'; // <- error here echo $foo; I get a parse error :| 回答1: If you want to assign a

Difference between $a=&$b , $a = $b and $a= clone $b in PHP OOP

一曲冷凌霜 提交于 2019-12-23 17:09:26
问题 What is the difference between $a = &$b , $a = $b and $b = clone $a in PHP OOP? $a is an instance of a class. 回答1: // $a is a reference of $b, if $a changes, so does $b. $a = &$b; // assign $b to $a, the most basic assign. $a = $b; // This is for object clone. Assign a copy of object `$b` to `$a`. // Without clone, $a and $b has same object id, which means they are pointing to same object. $a = clone $b; And check more info with References, Object Cloning. 回答2: // $a has same object id as $b.

Dll reference of one project into another project

时间秒杀一切 提交于 2019-12-23 15:59:20
问题 I have 2 projects, one built in VB.NET and another in C#.NET. I want to use certain functionality of VB.NET into C#.NET and hence I have added the dll file of VB.NET solution into C#.NET as a reference by browsing the dll from my system. Say dll name for VB.NET is myData.dll In my C#.NET project I am trying to declare it as a namespace i.e. "using myData;" and its giving me an error of "Type or namespace name could not be found" Am I missing something?? 回答1: A clue about how your VB.NET