I am new in this language.....but..i want to know this...

is VB-

you have SUB AND FUNCTION

Ths sub is just a procees...Doesnt return nothing...
and the function is that a function but returns a value


in Csharp...did you use sub and functions????

Dani AI

Generated

Short answer to : C# does not use VB's Sub and Function keywords — it has methods. and were on the right track. A few practical points and gotchas that often confuse people coming from VB.

Parameter passing: VB's ByVal/ByRef concepts map to C# value semantics and the ref/out keywords, but they behave differently. As hinted, ByRef is not always just ref — sometimes out is the correct match. Key rules: ref requires the variable be initialized before the call; out does not, but the called method must assign it before returning. See Microsoft docs for details on ref and out (ref, out).

Small examples showing the difference:

void Swap(ref int a, ref int b)
{
    int t = a;
    a = b;
    b = t;
}

bool TryParseInt(string s, out int value)
{
    return int.TryParse(s, out value);
}

Other notes: methods live on types (classes/structs), can be static (shared) or instance, support overloading, and in modern C# you also have local functions and async methods that return Task/Task<T>. For full syntax, modifiers, and patterns check the official Methods reference (Methods (C#)).

Recommended Answers

All 8 Replies

No they are all "methods" the only difference is if you dont want to return anything you say it returns "void" eg nothing

I agree with LizR. C# is a C-like language, in C you have only functions, no subroutines.
When you want to "simulate" a subroutine in C, C# or C++ you use something like

void MyStuff()
{
     //do my stuff
}

When you use functions in a class you call them methods, but what's in a name?
Just use those "things" and happy programming!

and to extend upon ddanbe, you can also set the modifiers on the methods

public void MyStuff()
{
}

private void MyStuffAgain()
{
}

the access modifiers match except these
VB -> C# equivalent
Friend -> internal
Protected Friend -> internal protected

I am new in this language.....but..i want to know this...

is VB-

you have SUB AND FUNCTION

Ths sub is just a procees...Doesnt return nothing...
and the function is that a function but returns a value


in Csharp...did you use sub and functions????

No I give you and example to better understand

public sub x() = public void x ();
public shared sub x() = public static void x();
public Function x(byVal type a,ByRef type b) as type = public type x(type a, ref type b);

Jugortha, ByRef isn't always going to be c# ref, it will sometimes be out

if you aren't for sure, don't post information that may lead someone down the wrong path

Yes you have raison dikersonka but I try to simplify the existence to gooki2005

Yes you have raison dikersonka but I try to simplify the existence to gooki2005

What on earth does that mean?

Lol i think its some sort of way to say yes you are correct, but I thought i had a way to help gooki understand.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.