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

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 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;
}

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