Jump to content

Static classes

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
i have a question

i can do this job by instancing classes but i don't know how to do it with static classes

here is my code:


using System;


static class VoidFunkcija

{

    public static void Bezveze()

    {

        Console.WriteLine("Bok");

    }

}


static class IntFunkcija

{

    public static int Bezveze2(int a, int b)

    {

        int c;

        c = a + b;

        return c;

    }

}


static class Glavna

{

    static void Main()

    {

        Bezveze();


        int f;

        int g;


        f = Convert.ToInt32(Console.ReadLine());

        g = Convert.ToInt32(Console.ReadLine());


        Console.Write(Bezveze2(f, g));

        Console.ReadKey();

    }

}

and debugger says that Bezveze and Bezveze2 functions doesn't exist in the current context

what did i missed???

#2
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 242 posts
static methods need the full class.methodname to be used. So change 'Bezveze()' to 'VoidFunkcija.Bezveze()'. Hopefully you can figure out how to use Bezveze2 :)

#3
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
i figured :D




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users