Expected Class Delegate Enum Interface Or Struct Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more expected class delegate enum interface or struct in mvc about Stack Overflow the company Business Learn more about hiring developers or posting expected class delegate enum interface or struct error in c# ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack error 1 expected class delegate enum interface or struct error in c# Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “Expected class, delegate, enum, interface or struct” error on public static expected class delegate enum interface or struct (cs1518) string MyFunc(). What's an alternative to “string”? up vote 11 down vote favorite 3 I'm getting an error when I attempt to use the following static function. Error: Expected class, delegate, enum, interface, or struct Function (and class): namespace MyNamespace { public class MyClass { // Some other static methods that use Classes, delegates, enums, interfaces, or structs public static string MyFunc(string myVar){ string myText = myVar; //Do some
Expected Class Delegate Enum Interface Or Struct Void
stuff with myText and myVar return myText; } } } This is causing the compiler to angrily (in red) underline the string part of public static string. So, I assume this means string is not a class, delegate, enum, interface, or struct. What can I use instead of string to return a string or string-like object? There doesn't appear to be a String (capital S) class in C#. Edit: Bracket mis-match with some commented code - the above code works correctly, my actual mis-matched code didn't. Thanks! c# compiler-errors static-methods share|improve this question edited May 14 '14 at 13:26 Irvin Dominin 22.9k64068 asked Jan 28 '11 at 2:14 Peach 74911222 add a comment| 2 Answers 2 active oldest votes up vote 21 down vote accepted You need to put the method definition into a class/struct definition. Method definitions can't appear outside those. share|improve this answer answered Jan 28 '11 at 2:15 Femaref 48.3k391132 (I thought) It was. Updating code to include those details... –Peach Jan 28 '11 at 2:17 4 And I'm quite sure it isn't, at least I didn't encounter this particular compiler error with any other cause. Check your braces, that could be a reason as well. –Femaref J
here for a quick overview of the site Help Center Detailed answers to any questions
How To Solve Expected Class Delegate Enum Interface Or Struct
you might have Meta Discuss the workings and policies of this type or namespace definition or end-of-file expected site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers identifier expected c# 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 http://stackoverflow.com/questions/4824194/expected-class-delegate-enum-interface-or-struct-error-on-public-static-str community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error: expected class,delegate,enum,interface or struct up vote 0 down vote favorite I get the following error on the code below: expected class,delegate,enum,interface or struct. This happens when hovering on GH_ObjectResponse, what am I http://stackoverflow.com/questions/11769866/error-expected-class-delegate-enum-interface-or-struct doing wrong? public class SettingsComponentAttributes : GH_ComponentAttributes { public SettingsComponentAttributes(IGH_Component SettingsComponent) : base(SettingsComponent) {} } public override GH_ObjectResponse RespondToMouseDoubleClick( GH_Canvas sender, GH_CanvasMouseEvent e) { ((SettingsComponent)Owner).ShowSettingsGui(); return GH_ObjectResponse.Handled; } c# visual-studio-2010 syntax-error share|improve this question edited Jun 4 at 17:33 Uwe Keim 22.6k25100159 asked Aug 2 '12 at 1:32 Arthur Mamou-Mani 83832551 add a comment| 2 Answers 2 active oldest votes up vote 5 down vote accepted Your method is not declared inside the class... try this instead: public class SettingsComponentAttributes : GH_ComponentAttributes { public SettingsComponentAttributes(IGH_Component SettingsComponent) : base(SettingsComponent) { } public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e) { ((SettingsComponent)Owner).ShowSettingsGui(); return GH_ObjectResponse.Handled; } } share|improve this answer answered Aug 2 '12 at 1:34 Glen Hughes 2,466917 add a comment| up vote 1 down vote Watch your brackets. It should be: public class SettingsComponentAttributes : GH_ComponentAttributes { public SettingsComponentAttributes(IGH_Component SettingsComponent) : base(SettingsComponent) {} public override GH_ObjectResponse RespondToMouseDoubleClick(GH_Canvas sender, GH_CanvasMouseEvent e) { ((SettingsComponent)Owner).ShowSettingsGui(); return GH_ObjectResponse.Handled; } } share|improve this answer
Class1 { private CardType _cardTypes; } public bool IsValidCardType(string cardNumber) { // AMEX -- 34 or 37 http://www.codeproject.com/Questions/249915/Expected-class-delegate-enum-interface-or-struct?display=Print -- 15 length if ((Regex.IsMatch(cardNumber, "^(34|37)")) && ((_cardTypes & CardType.Amex) https://msdn.microsoft.com/en-us/library/8tfcb4de.aspx != 0)) return (15 == cardNumber.Length); // MasterCard -- 51 through 55 -- 16 length else if ((Regex.IsMatch(cardNumber, "^(51|52|53|54|55)")) && ((_cardTypes & CardType.MasterCard) != 0)) return (16 == cardNumber.Length); // VISA -- 4 -- 13 and 16 length else expected class if ((Regex.IsMatch(cardNumber, "^(4)")) && ((_cardTypes & CardType.VISA) != 0)) return (13 == cardNumber.Length || 16 == cardNumber.Length); // Diners Club -- 300-305, 36 or 38 -- 14 length else if ((Regex.IsMatch(cardNumber, "^(300|301|302|303|304|305|36|38)")) && ((_cardTypes & CardType.DinersClub) != 0)) return (14 == cardNumber.Length); // enRoute -- 2014,2149 -- 15 length else expected class delegate if ((Regex.IsMatch(cardNumber, "^(2014|2149)")) && ((_cardTypes & CardType.DinersClub) != 0)) return (15 == cardNumber.Length); // Discover -- 6011 -- 16 length else if ((Regex.IsMatch(cardNumber, "^(6011)")) && ((_cardTypes & CardType.Discover) != 0)) return (16 == cardNumber.Length); // JCB -- 3 -- 16 length else if ((Regex.IsMatch(cardNumber, "^(3)")) && ((_cardTypes & CardType.JCB) != 0)) return (16 == cardNumber.Length); // JCB -- 2131, 1800 -- 15 length else if ((Regex.IsMatch(cardNumber, "^(2131|1800)")) && ((_cardTypes & CardType.JCB) != 0)) return (15 == cardNumber.Length); else { // Card type wasn't recognised, provided Unknown is in the CardTypes property, then // return true, otherwise return false. if ((_cardTypes & CardType.Unknown) != 0) return true; else return false; } } Posted 5-Sep-11 2:48am raj_sagoo129 Updated 5-Sep-11 3:25am Mika Wendelius323.1K v2 Comments Mika Wendelius 5-Sep-11 8:50am Could you post the code giving the error... raj_sagoo 5-Sep-11 9:23am code moved to the question 5 solutions Top Rated M
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. MSDN Library MSDN Library MSDN Library MSDN Library Design Tools Development Tools and Languages Mobile and Embedded Development .NET Development Office development Online Services Open Specifications patterns & practices Servers and Enterprise Development Speech Technologies Web Development Windows Desktop App Development TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. Compiler Error CS1518 Other Versions Visual Studio 2008 Visual Studio 2005 Visual Studio .NET 2003 Expected class, delegate, enum, interface, or structA declaration was found that is not supported in a namespace. Inside a namespace, the compiler accepts only classes, structs, enums, interfaces, namespaces, and delegates.ExampleThe following sample generates CS1518: Copy // CS1518.cs namespace x { sealed class c1 {}; // OK namespace f2 {}; // OK sealed f3 {}; // CS1518 } Show: Inherited Protected Print Export (0) Print Export (0) Share IN THIS ARTICLE Is this page helpful? Yes No Additional feedback? 1500 characters remaining Submit Skip this Thank you! We appreciate your feedback. Dev centers Windows Office Visual Studio Microsoft Azure More... Learning resources Microsoft Virtual Academy Channel 9 MSDN Magazine Community Forums Blogs Codeplex Support Self support Programs BizSpark (for startups) Microsoft Imagine (for students) United States (English) Newsletter Privacy & cookies Terms of use Trademarks © 2016 Microsoft © 2016 Microsoft