Click here to Skip to main content
15,909,546 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
using System;

namespace ConsoleApp21
{
    class Program
    {
        static void Main(string[] args)
        {
       
        public enum Humidity
        {
            [System.ComponentModel.DescriptionAttribute("OUT OF RANGE")]
            Invalid = 0
,
            [System.ComponentModel.DescriptionAttribute("TOO DRY")]
            VeryLow = 1
,
            [System.ComponentModel.DescriptionAttribute("DRY")]
            Low = 2
,
            [System.ComponentModel.DescriptionAttribute("LITTLE DRY")]
            Medium = 3
,
            [System.ComponentModel.DescriptionAttribute("LITTLE MOIST")]
            High = 4
,
            [System.ComponentModel.DescriptionAttribute("MOİST")]
            VeryHigh = 5
        } 
        private static Humidity
        GetHumidityLevel
        (
          int Percent
        )
        {
            Humidity result = Humidity.Invalid;

            if ((Percent >= 0) && (Percent <= 100))
            {
                result = (Humidity)((Percent - 1) / 20 + 1);
            }

            return (result);
        }

        private static System.Collections.Generic.Dictionary<Humidity, string> hum =
          new System.Collections.Generic.Dictionary<Humidity, string>();

        private static string
        GetHumidityDescription
        (
          Humidity Level
        )
        {
            string result;

            if (!hum.TryGetValue(Level, out result))
            {
                System.Reflection.FieldInfo f = typeof(Humidity).GetField
                (
                  Level.ToString("G")
                ,
                  System.Reflection.BindingFlags.Public
                  |
                  System.Reflection.BindingFlags.Static
                );

                System.ComponentModel.DescriptionAttribute[] a = (System.ComponentModel.DescriptionAttribute[])
                  f.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);

                hum[Level] = result = a[0].Description;
            }

            return (result);
        }
    }
    }


What I have tried:

This is not my code but someone give it to me for help and I tried to submit it to my page and there is an error about waiting about } I did't get clearly. I'm training with this c# for 3 weeks so I don't have soo much info about it but I want to learn. I'm not being lazy just you guys can say to me how I can solve this and I can do it. I dont need new codes or new stuffs.
Posted
Updated 28-Oct-20 5:52am
Comments
PIEBALDconsult 28-Oct-20 11:41am    
*Banging head on desk* Seriously?
Richard MacCutchan 28-Oct-20 11:57am    
That's what you get for being Mr Nice Guy.
PIEBALDconsult 28-Oct-20 12:02pm    
Being a wise-a... guy you mean.
Richard MacCutchan 28-Oct-20 12:04pm    
I would never be so rude (well, hardly ever).
PIEBALDconsult 28-Oct-20 12:16pm    
Good-natured badinage from my esteemed colleagues is always appreciated.

Start by looking at the error message closely - it will give you a filename, a line and probably a column number. These will help you work out what the problem is by looking at the exact code that generates it.

In this case, there are a few problems with that code but teh one you have reported is probably here:
static void Main(string[] args)
{

public enum Humidity
{
You can't define an enum within the body of a method: you need to move it outside the Main method and to the class level by closing the method:
static void Main(string[] args)
{
}

public enum Humidity
{
Your app won't do anything at all - because Main is empty - but that error will go!

BTW: do yourself a favour and be consistent.
When you use two different styles in the same file, it makes it very difficult to read.
Compare:
C#
public static void Main(string[] args)
{
...
}       
private static string
GetHumidityDescription
(
    Humidity Level
)
{
...
With:
C#
public static void Main(string[] args)
{
...
}       
private static string GetHumidityDescription(Humidity Level)
{
...

And never, ever, put commas on a line of their own!
 
Share this answer
 
Comments
CHill60 28-Oct-20 11:51am    
Beat me to it. 5
PIEBALDconsult 28-Oct-20 11:53am    
Ahem, that's so you know I wrote it.
OriginalGriff 28-Oct-20 12:09pm    
That's cruel!
Funny, but ... you do realize he'll grow up using your new style and you'll end up maintaining it, don't you? :laugh:
PIEBALDconsult 28-Oct-20 12:17pm    
I'm sure I have done no damage to his career flipping burgers.
Member 14976913 28-Oct-20 12:27pm    
I'm sure that one day I'll learn that things and you will want from me a job for some money. Lets dont talk about it to the that day. You are so rude and this give me more power to do it. MAYBE I DONT KNOW HOW WRITING A CODE BUT YOU DON'T KNOW ANYTHİNG ABOUT BEING HUMAN OR NICE GUY. MAYBE I CANT DO MY OWN CODE BUT YOU CAN'T BE REAL HUMAN AND CAN'T HAVE NORMAL HUMAN FEELINGS ANYTIME IN YOUR LIFE. I WON'T USE THIS WEB-SITE ANYMORE BUT THANKS TO ANSWER FROM THE OTHER PERSON WHO IS TRYIN TO HELP ME. STOP TRYING TO BE FUNNY WITH OTHER HUMANS FAILS...
This is the problem with just using other people's code...you learn nothing from it, and given your issue you clearly know nothing about the basics of c# and you don't really deserve to pass your homework.

Change

C#
static void Main(string[] args)
{


to

C#
static void Main(string[] args)
{ }


And just FYI, the person who gave you that code was trolling you, if you submit it you'll still fail. Furthermore your teacher will almost certainly know you are submitting someone else's work.
 
Share this answer
 
Comments
PIEBALDconsult 28-Oct-20 12:04pm    
:D Aw, c'mon, it's mother beautiful code, it works and everything.
I suspect the teacher is trolling the class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900