Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

C# issue (Don't Know Where to Put This)


  • Please log in to reply
17 replies to this topic

#1 sonic_944

sonic_944

  • Members
  • 117 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:55 AM

Posted 21 January 2014 - 11:48 AM

So I am extremely new to programming and I'm learning C#. So I was following this tutorial (and taking notes) when I somehow came across this error: http://i.imgur.com/MXjVIHw.png. http://i.imgur.com/eiw7NeY.png.


Edited by hamluis, 21 January 2014 - 12:26 PM.
Moved from Win 7 to Programming - Hamluis.


BC AdBot (Login to Remove)

 


m

#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 PM

Posted 21 January 2014 - 02:57 PM

Feel free to include your  code next time. there are special BB tags just for code. That way we can see what you did, and we can easily alter your code.

 

In short, the problem is exactly as it says. Wii_U is a namespace, not a data type. In C# (amongst other languages), you need to declare a variable type with the variable. For instance:

//This is how to instantiate a string
String s = "";

 

It has a data type, a variable name, and a value. Wii_U is a namespace, not a data type. I can't help you beyond that because I don't know what your are trying to do, and I have no time to watch a video.

 

In your second image, you are having sort of the same problem. You have a variable name and a value, but you do not have a data type. You also have a semi-colon where it shouldn't be, at the end of the line that says

public Of30000

 

Again, without knowing what you are trying to accomplish at this point, we cant do much more than guess at what you are trying to do.



#3 sonic_944

sonic_944
  • Topic Starter

  • Members
  • 117 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:55 AM

Posted 21 January 2014 - 03:11 PM

I'm sorry, I forgot about this topic, but I have successfully fixed the code. Thanks though.



#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 PM

Posted 21 January 2014 - 06:13 PM

You forgot about it in 4 hours? :blink:



#5 sonic_944

sonic_944
  • Topic Starter

  • Members
  • 117 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:55 AM

Posted 21 January 2014 - 06:19 PM

I have terrible memory. Maybe that's why I suck at school.

 

EDIT: How do I show intellisense all the time instead of randomly.


Edited by sonic_944, 21 January 2014 - 06:30 PM.


#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 PM

Posted 22 January 2014 - 12:59 AM

I have a terrible memory, and I used to suck at school too. But that is because school never taught me in a way that was appropriate for the way I learn.

 

Sorry if this seems like a weird question, but what IDE are you talking about, and what Intellisence hints are you expecting? I have only used a few IDEs, but all of them are reasonable about identifying variables and functions.


Edited by groovicus, 22 January 2014 - 01:00 AM.


#7 sonic_944

sonic_944
  • Topic Starter

  • Members
  • 117 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:55 AM

Posted 22 January 2014 - 06:13 AM

"Microsoft Visual Studio C# 2013". Also another coidng issue: it says identifier needed.

 

public class1 (identifier needeed) (string name);



#8 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 PM

Posted 22 January 2014 - 11:27 AM

Would have to see your code.



#9 sonic_944

sonic_944
  • Topic Starter

  • Members
  • 117 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:55 AM

Posted 22 January 2014 - 11:29 AM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Wii_U
{
    public class CLass1 (  string name)
    class Class1
    {
    }
}

}
 



#10 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 PM

Posted 22 January 2014 - 09:03 PM

There are a couple of typos in that sample, along with incorrect syntax. Try should get you a little closer.

namespace Wii_U
{
    public class Class1
    {
      public Class1(string name)
      {
         Debug.WriteLine("The name is " + name);
      }
   }
}

 

Some explanation:

public class Class1 - This is the class declaration. The class declaration does not take a parameter.

public Class1(string name) - This is a constructor that takes a string as a parameter.

 

You would instantiate your class something like this then:

Class1 c = new Class1("Fibber Mcgee");

 

When you instantiate it, you should see the following in the IDE output window:

The name is Fibber McGee

 

********************************************************************************************

That should fix your issue, but this code doesn't do anything by itself. It needs to be instantiated by some other code. Here is an example of how that could be done:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace mynamespace
{
    class Program
    {
        static void Main(string[] args)
        {
            Debug.WriteLine("*********************************  Starting");
            Class1 c = new Class1("Fibber McGee");
        }
    }

    public class Class1
    {
        public Class1(string name)
        {
            Debug.WriteLine("The name is " + name);
        }
    }
}

 

This example looks really complex, and I get that it might look a little intimidating. All I am doing is putting everything into a sort of framework that I can use for testing. In order to run a C# app, you need a main method, so I just provided the code to do that. I am completely ignoring the use of the namespace because it is unimportant for this example.



#11 sonic_944

sonic_944
  • Topic Starter

  • Members
  • 117 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:55 AM

Posted 23 January 2014 - 06:21 AM

Thank you. I ditched the tutorial, for now, so I am reading a book called "Sams Teach You Visual C# In 24 Hours".



#12 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 PM

Posted 23 January 2014 - 10:33 AM

Ok. Just as long as you don't really believe you can learn any language in 24 hours. :) The '24 hours' part is for programming professionals who already know how to program, and just need a reference to understand conventions particular to a language.

 

Have you seen Microsoft Virtual Academy?



#13 sonic_944

sonic_944
  • Topic Starter

  • Members
  • 117 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:55 AM

Posted 25 January 2014 - 07:28 PM

Im on this video:http://www.microsoftvirtualacademy.com/Content/ViewContent.aspx?et=3371&m=3355&ct=18145#?fbid=RccBI16VHU1 and I'm stuck on 8:00 in.

 

private static string myBubba(string name);

{

 

    return String.Format("Hello world, {0}", name);

 

   return "Hello world" + name;

 

}


Edited by sonic_944, 25 January 2014 - 08:07 PM.


#14 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:55 PM

Posted 25 January 2014 - 07:50 PM

Please, if you are going to ask for my time to answer a question, please take the time to explain what you are trying to do, show us what you did, and tell us what really happened. If there is an error message, post the error message. It is a little unreasonable to ask for help without providing some basic information, don't you think?



#15 sonic_944

sonic_944
  • Topic Starter

  • Members
  • 117 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:12:55 AM

Posted 25 January 2014 - 08:07 PM

Yo're right. My fault. I was following how to create methods , until it says on the String.Format "is used as a method, but used like a type". And for the name (last one in the parameter field) says "The type or namespace name 'name' could not be found." Both have read squiggly lines under them. I want to add "Hello world" to name.

 

P.S: I edit my code.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users