Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

What an awesome programming language

Name: Anonymous 2012-10-09 14:34

Pretty much any language other than C#:


  gun.transform.localPosition.x = newPos;


C#:


  gun.transform.localPosition.x = newPos;

error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.localPosition'. Consider storing the value in a temporary variable


Suggested C# workaround:


  gun.transform.localPosition.x = new Vector3(newPos, gun.transform.localPosition.y, gun.transform.localPosition.z);


10/10 would bang

Name: Anonymous 2012-10-09 14:48

this is why javascript is the future; operator overloading actually works correctly

Name: Anonymous 2012-10-09 14:51

>>2
operator overloading
It would be a great improvement if operator overloading was where C# fell apart...  C# can't even handle operators.  Just simple assignment is illegal.

Name: Anonymous 2012-10-09 14:55

thats pretty much the only flaw in c#

Name: Anonymous 2012-10-09 14:58

>>3
except you have to be fucking with properties to create that kind of assignment issue:


        [TestMethod]
        public void TestMethod1(){
            var t = new Test();
            t.TestVec = new Vector3();
            t.TestVec.X = 5;//wont  compile
           
        }

        class Test{
            public Vector3 TestVec { get; set; }
        }

Name: Anonymous 2012-10-09 15:10

>>4
Saying that being unable to assign values to variables is "pretty much the only flaw" in a language is like saying that the writing, acting, and directing were pretty much the only flaws in Battlefield Earth.

C#TM: The Battlefield Earth of programming languages.

Name: Anonymous 2012-10-09 15:44

Do you not understand the different between getting a member by reference, and getting a member by value?

Name: Anonymous 2012-10-09 15:45

>>6

The only issue is that it makes perfect sense. Op is using a struct type in a getter/setter scenario. The following example should help it make some sense. The equivalent code in C++ would be:


int main(){
    ContainerClass c = new ContainerClass;
    c.SetVec( new Vector3(x,y,z));
    c.GetVec().X = 5;//since GetVec returns a valuetype, changing X to 5 has no affect on the Vector3 in ContainerClass
        //in order to prevent former java programmers from fucking themselves over because they don't know about structs, this would raise a compile error in C#
}

class ContainerClass{
private Vector3 _vec;//vector3 is a struct

public Vector3 GetVec(){return _vec;}
public void SetVec(Vector3 vec){_vec = vec}

}



The reason Java doesn't have this praoblem is that it treated everything as a reference type, the only value types are int, float, double, etc.

OP, the actual fix to your issue is to make gun.transform.localPosition a reference type, rather than a value type.

Name: Anonymous 2012-10-09 15:53

goddamn and to think c# is nice enough to throw a compile error for you, op. god speed programming in c++ or in any other language that doesn't hold your hand.

Name: 2000 2012-10-09 15:57

Spaghetti

Name: Anonymous 2012-10-09 15:59

What I hate about Sepples, is the fact that everyone says I should make all attributes private and define getters/setters for each one.
This is dumb as fuck. The property() function used in Python is much better.

Name: Anonymous 2012-10-09 16:12

>>11
eval()

Name: Anonymous 2012-10-09 16:16

>>12
c# has eval too!

public static object Eval(string sCSCode) {
    CSharpCodeProvider c = new CSharpCodeProvider();
    ICodeCompiler icc = c.CreateCompiler();
    CompilerParameters cp = new CompilerParameters();

    cp.ReferencedAssemblies.Add("system.dll");
    cp.ReferencedAssemblies.Add("system.xml.dll");
    cp.ReferencedAssemblies.Add("system.data.dll");
    cp.ReferencedAssemblies.Add("system.windows.forms.dll");
    cp.ReferencedAssemblies.Add("system.drawing.dll");

    cp.CompilerOptions = "/t:library";
    cp.GenerateInMemory = true;

    StringBuilder sb = new StringBuilder("");
    sb.Append("using System;\n");
    sb.Append("using System.Xml;\n");
    sb.Append("using System.Data;\n");
    sb.Append("using System.Data.SqlClient;\n");
    sb.Append("using System.Windows.Forms;\n");
    sb.Append("using System.Drawing;\n");

    sb.Append("namespace CSCodeEvaler{ \n");
    sb.Append("public class CSCodeEvaler{ \n");
    sb.Append("public object EvalCode(){\n");
    sb.Append("return " + sCSCode + "; \n");
    sb.Append("} \n");
    sb.Append("} \n");
    sb.Append("}\n");

    CompilerResults cr = icc.CompileAssemblyFromSource(cp, sb.ToString());
    if (cr.Errors.Count > 0) {
        return null;
    }

    System.Reflection.Assembly a = cr.CompiledAssembly;
    object o = a.CreateInstance("CSCodeEvaler.CSCodeEvaler");

    Type t = o.GetType();
    MethodInfo mi = t.GetMethod("EvalCode");

    object s = mi.Invoke(o, null);
    return s;
}

Name: Anonymous 2012-10-09 16:29

>>8
While this is actually helpful information (as such, not sure why it was posted on /prog/), OP can't make the suggested fix because:

UnityEngine.Transform.localPosition

This is apparently part of the Unity engine, and the developer doesn't have access to the source.  Probably.

Name: Anonymous 2012-10-09 17:17

I use c#at work And I went in hating it.It's Startingto grow on me though  it has some solid net abilities

Name: Anonymous 2012-10-09 18:03

C++

    ContainerClass c = new ContainerClass;
What?

Name: Anonymous 2012-10-09 18:59

>>13
SLOW AS FUCK

Name: Anonymous 2012-10-09 19:08

>>17
Get a better compiler.

Name: Anonymous 2012-10-09 21:27

>>18
i do. it's called V8.

Name: Anonymous 2012-10-09 22:26

>>19
V8
fast
Funny joke

Name: Anonymous 2012-10-09 22:54

>>19
fuck off back to le hacker news javashit homojew

Name: Anonymous 2012-10-10 0:29

>>20,21
lol mad

javascript beats the pants off cshit in any category you care to name. why else do you think microsoft chose it for metro?

Name: Anonymous 2012-10-10 0:37

>>22
my hero

Name: Anonymous 2012-10-10 9:55

>>22-23
Shalom!

Name: Anonymous 2012-10-10 10:34

>>24
what does that mean

Name: Anonymous 2012-10-10 10:47

>>25
it means fuck off back to the imageboards fagshit kike

Don't change these.
Name: Email:
Entire Thread Thread List