Error 1 A New Expression Requires Or After Type C
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies a new expression requires () or [] after type unity of this site About Us Learn more about Stack Overflow the company Business
A New Expression Requires () After Type
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up A new expression requires () or [] after type compilation error - C# up vote 5 down vote favorite The following code for a co-worker throws the following error when he tries to compile it using VS 2008: Error: A new expression requires () or [] after type Code: MyClass Structure: public class MyClass { public MyClass() {} public string Property1 { get; set; } public string Property2 { get; set; } } Sample Source Code: List x = new List(); x.Add(new MyClass { Property1 = "MyValue", Property2 = "Another Value" }); It "works on my machine", but not his. Any idea why? UPDATE He is targeting the 3.5 .NET framework He is using the System.Collections.Generics namespace The MyClass object does have a constructor UPDATE 1: @Funky81 - Your example and my example were able to compile on my PC. Update 2: Included schema of MyClass in sample UPDATE 3: @DK - I had my co-worker add the following configuration section to his application: And he received the following compilation error: Unrecognized element 'providerOption'. c# visual-studio-2008 .net-3.5 share|improve this question edited Mar 30 '09 at 22:09 asked Dec 23 '08 at 18:14 Michael Kniskern 10k50132198 Perhaps your buddy is using the C# 2.0 compiler? –yfeldblum Dec
Answers Feedback Issue Tracker Blog Evangelists User Groups Navigation Home Unity Industries Showcase Learn Community Forums Answers Feedback Issue Tracker Blog Evangelists User Groups Get Unity Asset Store Unity account You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account Language Chinese Spanish Japanese Korean Portuguese Ask a question Spaces Default Help Room META Moderators Topics Questions Users Badges Home / 1 Question by blast3r1 · Jan 05, 2014 at 07:26 AM · http://stackoverflow.com/questions/389644/a-new-expression-requires-or-after-type-compilation-error-c-sharp cs1526 (CLOSED)how do i fix error CS1526 (CLOSED) ANSWERED i got this error on a project im working on i stay up late and couldn't fix it help Assets/script/player physics.cs(61,15): error CS1526: A new expression requires () or [] after type this is my script using UnityEngine; using System.Collections; [RequireComponent (typeof(BoxCollider))] public class playerphysics : MonoBehaviour { public LayerMask collisionMask; private BoxCollider collider; http://answers.unity3d.com/questions/609535/how-do-i-fix-error-cs1526.html private Vector3 s; private Vector3 c; private float skin = .005f; [HideInInspector] public bool grounded; Ray ray; RaycastHit hit; void Start() { collider = GetComponent(); s = collider.size; c = collider.center; } public void Move(Vector2 moveAmount) { float deltaY = moveAmount.y; float deltax = moveAmount.x; Vector2 p = transform.position; for (int i = 0; i<=3; i ++) { float dir = Mathf.Sign(deltaY); float x = (p.x + c.x - s.x/2) + s.x/2 * i; // Left,centre and then rightmost point of collider float y = p.y + c.y + s.y/2 * dir; // Bottom of collider ray = new Ray(new Vector2(x,y), new Vector2(0,dir)); if (Physics.Raycast(ray,out Hit.Mathf.Abs(deltaY).collisionorMask)) { //Get Distance between player and ground float dst = Vector3.Distance(ray.origin, hit.point); //Stop player's downwards movement after coming within skin width of a collider if(dst > skin) { deltaY = dst + skin; } else { deltaY =0; } grounded = true; break; } } Vector2 finalTransform = new Vector2(deltax,deltaY transform.Translate(finalTransform); } } Comment Add comment · Show 1 10 |3000 characters needed characters left characters exceeded ▼ Viewable by all users Viewable by moderators Viewable by moderators and the
Answers Feedback Issue Tracker Blog Evangelists User Groups Navigation Home Unity Industries Showcase Learn Community Forums Answers Feedback Issue http://answers.unity3d.com/questions/653547/error-cs1526-a-new-expression-requires-or-after-ty.html Tracker Blog Evangelists User Groups Get Unity Asset Store Unity account https://social.msdn.microsoft.com/Forums/vstudio/en-US/ea7b242a-7f74-4924-8283-c9ed47bb0742/a-new-expression-requires-or-after-type?forum=csharpgeneral You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account Language Chinese Spanish Japanese Korean Portuguese Ask a question Spaces Default Help Room META Moderators Topics Questions Users Badges a new Home / 0 Question by NutellaDaddy · Mar 02, 2014 at 06:51 AM · c#inventorydictionary error CS1526: A new expression requires () or [] after type For some reason when I try to add something to the dictionary it says the above error. It's on line 106 using UnityEngine; using System.Collections.Generic; public class inventoryV1 : MonoBehaviour a new expression { public static bool inventoryOn = false; //GUI FONT AND SIZE private Vector2 windowPosition = new Vector2(300,0); private Vector2 windowSize = new Vector2(745, 750); private Vector2 closePosition = new Vector2(705,9); private Vector2 closeSize = new Vector2(24,24); private Vector2 inventoryTitlePosition = new Vector2(245,11); private Vector2 inventoryTitleSize = new Vector2(125,50); private Vector2 playerTitlePosition = new Vector2(17,11); private Vector2 playerTitleSize = new Vector2(100,50); private Vector2 craftingTitlePosition = new Vector2(17,414); private Vector2 craftingTitleSize = new Vector2(125,40); //Dictionary static public Dictionary inventoryNameDictionary; //WINDOW TEXTURES public Texture inventoryWindow; //BUTTON TEXTURES public Texture closeInventory; public Texture inventorySlot; //ACCESS CLASSES ItemClass itemObject = new ItemClass(); void Update () { //ON OR OFF if (Input.GetKeyUp (KeyCode.Tab)) { if (inventoryOn == false) { inventoryOn = true; } else if (inventoryOn == true) { inventoryOn = false; } if(Optionsmenu.isOptionsOn == true) { inventoryOn = false; } } } //GUI AND FUNCTIONALITY void OnGUI() { if (inventoryOn == true) { GUILayout.BeginArea(new Rect (windowPosition.x, windowPosition.y, windowSize.x, windowSize.y), inventoryWindow); //Close Button if (GUI.Button (new Rect (closePosition.x, closePosition.y, closeSize.x, closeSi
Languages , .NET Framework > Visual C# Question 0 Sign in to vote Dictionary myDictionary = new Dictionary myDictionary.Add("key1", "First Item"); -->I'm being told that "A new expression requires (), [], or {} after type" I don't know what change to make in order to correct it...I'm very new at this. Friday, August 08, 2014 1:59 AM Reply | Quote Answers 2 Sign in to vote You do not have to use () if you use any of {} or []: Dictionary myDictionary = new Dictionary(); Dictionary myDictionary = new Dictionary { {"key", "value"} }; string[] stringArray = new string[5]; Marked as answer by Kristin XieMicrosoft contingent staff, Moderator Monday, August 11, 2014 9:38 AM Friday, August 08, 2014 5:19 AM Reply | Quote 0 Sign in to vote You have omitted the (), your statement should be as follows: Dictionary myDictionary = new Dictionary (); myDictionary.Add("key1", "First Item"); To make an instance of an object you have to use a method. Marked as answer by Kristin XieMicrosoft contingent staff, Moderator Monday, August 11, 2014 9:37 AM Friday, August 08, 2014 2:14 AM Reply | Quote 0 Sign in to vote You need a pair of parentheses at the end of the line with the "new" on it. This tells the compiler to call the Dictionary's constructor. Dictionary myDictionary = new Dictionary(); Marked as answer by Kristin XieMicrosoft contingent staff, Moderator Monday, August 11, 2014 9:38 AM Friday, August 08, 2014 2:14 AM Reply | Quote All replies 0 Sign in to vote You have omitted the (), your statement should be as follows: Dictionary myDictionary = new Dictionary (); myDictionary.Add("key1", "First Item"); To make an instance of an object you have to use a method. Marked as answer by Kristin XieMicrosoft contingent staff, Moderator Monday, August 11, 2014 9:37 AM Friday, August 08, 2014 2:14 AM Reply | Quote 0 Sign in to vote You need a pair of parentheses at the end of the line with the "new" on it. This tells the compiler to call the Dictionary's co